I want to remove and add a control at runtime on a WinForm. The problem is, that the Control must have the exact same size, location and anchors as another one.
If the user opens the window and a certain criteria is fulfilled, I want to delete the old control and replace it by another.
So, I tried this:
RichTextBox InsideText = new RichTextBox();
InsideText.Location = InsideBox.Location;
InsideText.Size = InsideBox.Size;
Controls.Remove(InsideBox);
Controls.Add(InsideText);
But, as expected, it didn't work. The InsideBox
is not removed and the InsideText
not added.
What am I doing wrong? Is there a better approach to this?