Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset all the items in a form

Tags:

c#

winforms

reset

I was wondering, is there a way I can reset all the checkboxes, textboxes, numerics and other controls back to the default values without writing code for every control individually? This is the code I've tried, but doesn't seem to work:

for (int i = 0; i < this.Controls.Count; i++)
{
    this.Controls[i].ResetText();
}

EDIT:
I've fixed it by manually setting the control values, sorry for all the trouble >.<.

like image 606
Yuki Kutsuya Avatar asked Mar 22 '13 11:03

Yuki Kutsuya


1 Answers

You can create the form again and dispose the old one.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void btnReset_Click(object sender, EventArgs e)
    {
        Form1 NewForm = new Form1();           
        NewForm.Show();
        this.Dispose(false);
    }
}
like image 104
Angus Chung Avatar answered Sep 22 '22 10:09

Angus Chung