JDogg Posted August 26, 2003 Posted August 26, 2003 Hi. Can somebody tell me what's wrong with the following line: RaiseEvent CType(FMsg, frmMsg).btn(2).Move VB doesn't like CType's presence, but I can't refer to btn(2) without casting FMsg. I tried putting brackets around all of CType(FMsg, frmMsg).btn(2).Move but VB underlined the opening bracket and said "identifier expected" in the task list. Thanks in advance. Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 You can use RaiseEvent only to raise events that are in the class you are calling the RaiseEvent from. Take a look at this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmraiseevent.asp Quote
JDogg Posted August 26, 2003 Author Posted August 26, 2003 But if I take the RaiseEvent away and just call it directly, ie. CType(FMsg, frmMsg).btn(2).Move(ButtonLeft + 2820, ButtonTop) it says in the task list that Move() cannot be called directly, and I should use RaiseEvent. What should I do? Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 (edited) If you want to execute the code that you have in the handler of Move event then simply call the sub that is the handler, not the event. Edited August 26, 2003 by mutant Quote
JDogg Posted August 26, 2003 Author Posted August 26, 2003 sorry... I'm pretty new to VB... what do you mean by "class" the sub? Are you recommending something like this: RaiseEvent CType(FMsg.btn(2), Control).Move(ButtonLeft + 2820, ButtonTop) That may be the farthest thing from what you're suggesting; again there's parts of VB I completely don't understand. Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 Im very sorry, i was thinking of a class when writing this and wrote class instead of call :rolleyes: . (I edited my post) What I mean is that: DirectCast(FMsg, frmMsg).SubThatHandlesTheEvent(arguments) You would have to make that event handler sub public. Quote
JDogg Posted August 26, 2003 Author Posted August 26, 2003 I'm starting to see what you mean... I had to read up on exactly what "events" and "handlers" were... :) The thing I don't get now is that the "btn" that I refer to is just an array of buttons placed on frmMsg... so frmMsg just inherits the handlers for the buttons' move events... but these handlers are empty, they don't do anything, ie. they don't appear in the code for frmMsg, only in the drop down menu of methods at the top of the screen, and when I select one it's just an empty sub... u know what I mean? Quote
*Experts* mutant Posted August 26, 2003 *Experts* Posted August 26, 2003 f im understanding you correctly you are trying to raise an event that does nothing, is that right? Then if you have no code for the event what is the prupose of it? :) Quote
JDogg Posted August 27, 2003 Author Posted August 27, 2003 Here's my situation: I need to move a button at runtime. I originally wrote the code in VB 6.0, and in order to move the button I just triggered its Move event. Now I need to be able to do that in VB .NET. I'm just learning about events, so I got confused earlier when you were talking about handlers. I want to actually trigger the event, not just respond to it. Quote
*Gurus* divil Posted August 28, 2003 *Gurus* Posted August 28, 2003 Why not just do myButton.Location = New Point(x, y) ? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.