Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset a form to its default appearance, after interaction with user

Tags:

c#

winforms

I wanted to get default view of my form after some interaction with user. In other words after some changes that has been implied by user, what command will return the form to the initial pop up appearance? I have many controls, and calculations, so I dont want to go over the control one by one and set them null or their default value. It would be great, as if I initate the form once more, some how.

like image 353
Amir Avatar asked Dec 21 '25 23:12

Amir


1 Answers

You could try clearing the controls on the form, then calling the InitializeComponent() method.

while (Controls.Count > 0)
{
    Controls[0].Dispose();
}
InitializeComponent();

EDIT:

Another Option that wouldn't cause any performance issues would be to utilize data binding. Create a data object that maps one to one with all of the fields you'd like to reset, then once it is time to reset the form simply set the data source of your form to a new instance of the data object.

like image 135
Charles Graham Avatar answered Dec 24 '25 14:12

Charles Graham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!