C #: What is the correct way to replace winform controls?

What is the correct way to replace one winform element with another element when something works? For example, I would like to replace the button with a text field in the same position and the same dimensions.

+3
source share
4 answers

If you don’t want (for some reason) to just change your visibility, you can add and remove them from the collection of form controls.

// contrived example...
private void Swap( Control toAdd, Control toRemove )
{
    this.Controls.Remove( toRemove );
    this.Controls.Add( toAdd );
}
+1
source

You can put them there and play with visibility

+1
source

Visible, (Visible = false) (Visible = true).

+1

, , , , , .

0
source

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


All Articles