Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: What is the proper way to swap winform controls?

Tags:

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

like image 420
William Avatar asked Dec 02 '09 01:12

William


1 Answers

If you do not (for some reason) want to simply change their visibility, you can add and remove them from the form's Controls collection.

// contrived example...
private void Swap( Control toAdd, Control toRemove )
{
    this.Controls.Remove( toRemove );
    this.Controls.Add( toAdd );
}
like image 190
Ed S. Avatar answered Oct 11 '22 16:10

Ed S.