Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Component events 2

Status
Not open for further replies.

PerthBok

Programmer
Mar 10, 2004
6
AU
Hi all. I've just started using VB.Net having used Delphi for a number of years. I seem to have problems with linking code to component events e.g. double click on a textbox and a textchange sub is created. Somehow though the link between the textbox and the subroutine gets broken and I can't see how to re-link the code to the components event. In Delphi it's simple as the component not only has a properties tabsheet but also has a methods tabsheet where events can be defined.

Help would be appreciated?

 
You can use AddHandler statement to sssociates an event with an event handler. Event handler is a procedure that will handle the event.

AddHandler TextBox1.TextChanged, New EventHandler(AddressOf TextBoxTextChanged)

Private Sub TextBoxTextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Your code goes here.
End Sub



 
If you add a TextBox (lets name it xtext1) and associate some event with it, and at some later point in time delete the textbox from your form, the associated event code remains in the form.

You can now add a new textbox (perhaps a class/component of your own) to the form, and rename it to the name of the original textbox eg xtext1

All that remains to be done to wire up the original event code is to add the "handles xtext.textchanged" to your original code for handling textchanged, or whatever the event maybe.

Deleting a control from a form will leave event code behind but it will only run given that you add back a control of the same name, and wire back up the event handler.






Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top