michaelrawi Posted September 19, 2006 Posted September 19, 2006 Supposed I want to create a button, and only need it's click event. Which one should I use: dim withevents button1 as windows.forms.button or dim button1 as windows.forms.button addhandler button1.click,addresof button1_click Which is the best and why? Thanks in advance Quote
michaelrawi Posted September 19, 2006 Author Posted September 19, 2006 Oh, I've look some of you have a fancy code tag with visual studio style / color. How can I do that ? Quote
Leaders snarfblam Posted September 19, 2006 Leaders Posted September 19, 2006 To make your VB code pretty, use the tags, and to make C# code look pretty use [CS] tags. As for the difference between WithEvents and AddHandler, the only difference is that WithEvents does the wiring automatically. That means that if you declare a WithEvents variable, every time you assign an object to the variable, the handlers are automatically attatched and every time you remove an object from a variable (assign another object or assign Nothing to the variable) the handlers are removed. AddHandler/RemoveHandler gives you more control over how event handlers at attatched and removed, but if WithEvents suits your needs then that is probably your best bet because it requires a smaller amount of clearer code (but is harder to port to other languages). Both methods basically compile down to the same thing. Quote [sIGPIC]e[/sIGPIC]
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.