Control Events

extraordinare

Member
Joined
Oct 4, 2005
Messages
11
Location
Orlando, FL
Programming Experience
Beginner
In my module I would like to respond to a click event raised by another object (my form). There seems to be little documentation on how to do this. The code I have so far is listed below. I am a very programmer, in fact have only been doing it for about year as a hobby so if I don't understand certain concepts I do apologize. :(
VB.NET:
'declares 3 thread objects
Dim t1 As Thread
Dim t2 As Thread
Dim t3 As Thread
 
Sub Main()
 
'intiated 3 thread objects
t1 = New Thread(AddressOf splash())
t2 = New Thread(AddressOf splash())
t3 = New Thread(AddressOf splash())
 
t.Start
 
End Sub
 
Private Sub Splash()
 
Dim form As New frmSplash
Application.Run(form)
form.Show
 
Dim b1 As Control 
Dim b2 As Control
 
b1 = form.btnEnter
b2 = form.btnExit
 
'need code here to respond to click event
 
 
End Sub
 
You will want to put your click event handler in the frmSplash class, not in a separate module. It will look something like this:

Private Sub btnEnter_Click(byval sender as Object, byval e as EventArgs) handles btnEnter.Click

'Do some stuff

End Sub

Also, you do not need to call form.Show after you call Application.Run(form).

If all you are trying to do in your Sub Main is start the program, just do this:

Sub Main()
Application.Run(new frmSplash)
End Sub
 
I might be misunderstanding what you are saying but I want to respond to the click event from within the module not the form. My goal is to start a thread based on the click event raised by the form. Also thank you for tip.
 
You can use the AddHandler statement to associate a procedure with an event at run time, but I'd suggest you just handle the event as normal in the form and call the method in the module form there.
 
Like I said, I really do think that you should handle the Button's Click event in the form as you normally would, and then just call some method in the module from that event handler. If you're determined to use AddHandler to directly associate the event with a method in the module, just look up AddHandler in the help for an example. The help system is ALWAYS the first place you should look.
 
I have looked up the help and do not understand it that's why I'm hear. I finally understand what you are talking about after reading the help files over and over and you are correct. What I'm going to is hide the three forms.
 
I'm glad you worked it out. I'm sorry if I seemed harsh but you were asking for something that was already available. If you wanted a code example handling an event using a Handles clause then mjb3030 had already provided one, and every event has a help topic that provides one too. If you wanted a code example for the AddHandler statement then its help topic provides one. I don't see why you should be able to understand something I provide if you don't understand them, hence my direction to the help system.
 
Back
Top