In my winform, in the designer.cs section of the form i have
this.Button1.Text = "&Click";
this.Button1.Click += new System.EventHandler(this.Button1_Click);
in form.cs
private void Button1_Click(object sender, System.EventArgs e)
{
//Code goes here.
}
In one part of the form i have a treeview and when that treeview contents are expanded, i need to rename the above button and wire up a different event
Button1.Name = "ButtonTest";
ButtonTest.Click += new System.EventHandler(this.ButtonTest_Click);
However this fails saying ButtonTest is not found, how do i dynamicall change the name of the button and call a different click event method?
private void ButtonTest_Click(object sender, System.EventArgs e)
{
//Code goes here.
}
Once this is called ButtonTest_Click, I need to rename it back to Button1, any thoughts?