Jan 15, 2012
"add controls at runtime" how to add code to the controls. kinda useless with no code, ehh? all results only told me how to add the control, that's it. well, this result is different. i will teach you firstly how to add controls at runtime, then how to apply code to them at runtime
View 6 Replies
Firstly, add the controls:
Now run it. do you have a button on the form? if yes, excellent. if not, you made a mistake. try again now how to add code? you may have noticed that when you double click on any control, it says private sub button1_click(blah, blah, blah) Handles button1.click where it says handles button1.click is what determines when the code executes under what event for what control (in this case the click event for the button1). this won't work when adding code at runtime. did you notice in the above example i added a with event, and addHandler? this is what creates the handler (same as Handles button1.click)
Now we add the code for the runtime control
Above, the addressOf button1_click tells the program to execute the sub button1_click when the button is clicked on (as determined by .click) but i know what you're thinking! your thinking "why would we even BOTHER doing this at runtime? isn't it easier to do it at design-time in the first place?" yes it is, providing your not writing a plugin. plugins are code based, not GUI (also reffered to as WYSIWYG). to update existing forms using plugins, you need to use this method.