Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Assigning one button to another

I have a GUI app, that has a button added. Within several plugin dll's, a new button is created and needs to be added to the GUI in place of the existing one.

Is there a way to simply say ButtonA = ButtonB? Or do I have to remove the button from the GUI at runtime and then add the new one?

Thanks.

like image 389
Darren Young Avatar asked May 09 '26 18:05

Darren Young


1 Answers

Or you can just link it to another handler, something like:

your old Click event handler

private void ButtonA_Click(object sender, EventArgs e)
{
//Do sth
}

your new Click Event handler (like if you create a new button)

private void ButtonB_Click(object sender, EventArgs e)
{
//Do sth
}

then you need to remove the first handler and add your new handler:

ButtonA.Click -= this.ButtonA_Click;
ButtonA.Click += new EventHandler(ButtonB_Click);
like image 94
Rami Alshareef Avatar answered May 11 '26 08:05

Rami Alshareef