cossy74
asked on
Dynamic Buttons and Events
Hi,
I have decalre a Button object in the form without actually droping the control onto the form.
At run time i decide whether or not to add the button.
How can i write an event handler for this button?
I have decalre a Button object in the form without actually droping the control onto the form.
At run time i decide whether or not to add the button.
How can i write an event handler for this button?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To complete the comments :
VB.NET syntax :
dim myButton as new Button
AddHandler myButton.Click, AddressOf me.Button_Click
if you want later to remove your handler :
RemoveHandler myButton.Click, AddressOf me.Button_Click
private sub Button_Click(sender as object, e as EventArgs)
end Sub
VB.NET syntax :
dim myButton as new Button
AddHandler myButton.Click, AddressOf me.Button_Click
if you want later to remove your handler :
RemoveHandler myButton.Click, AddressOf me.Button_Click
private sub Button_Click(sender as object, e as EventArgs)
end Sub
Oops... Forget it...
I haven't seen I was surfing the C# section... :">
I haven't seen I was surfing the C# section... :">
you could always drag a new button on the form, then set the Visible property to false, and add your event handler... then, if you need the button, set the Visible property to true
Button DynamicButton1= new Button();
b.Name="DynamicButton1"+co
Controls.Add(DynamicButton
DynamicButton1.Click+=new System.EventHandler(this.D
and put your DynamicButton1_Clicked somewhere in the same class