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.
A:
Put them next to each other and use the Visible property to hide one (Visible=false) and display the other (Visible=true).
Nate C-K
2009-12-02 01:18:20
+1
A:
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 );
}
Ed Swangren
2009-12-02 01:19:36