C # Assigning one button to another

I have a GUI application that has a button. A new button is created inside several dll plugins and must be added to the graphical interface instead of the existing one.

Is there a way to just say ButtonA = ButtonB? Or do I need to remove a button from the graphical user interface at runtime, and then add a new one?

Thank.

+3
source share
3 answers

Or you can just associate it with another handler, for example:

your old Click event handler

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

your new Click event handler (for example, 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 a new handler:

ButtonA.Click -= this.ButtonA_Click;
ButtonA.Click += new EventHandler(ButtonB_Click);
+3
source

(, ). , Form Controls . Controls.

, , , 5- , - :

this.Controls[4] = ButtonB;

100%, , GUI. ButtonB.Invalidate();

+1

, , , , Controls .Visible to false.

, , - .NET OnClick ( ).

0

Source: https://habr.com/ru/post/1790677/


All Articles