reset my form to its original state

Reset my form to its original state

Page 1 of 1

10 Replies - 51085 Views - Last Post: 03 February 2010 - 08:06 AM Rate Topic: -----

#1 cheeky01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-February 10

reset my form to its original state

Posted 02 February 2010 - 06:44 PM

How do i reset my form to its original state when the user clicks the exit button, i have text boxes and check boxes
Is This A Good Question/Topic? 0
  • +

Replies To: reset my form to its original state

#2 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: reset my form to its original state

Posted 02 February 2010 - 06:49 PM

What do you mean by original state?
Was This Post Helpful? 0
  • +
  • -

#3 cheeky01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-February 10

Re: reset my form to its original state

Posted 02 February 2010 - 06:51 PM

clear the text boxes and uncheck all the check boxes, and reset all the form
Was This Post Helpful? 0
  • +
  • -

#4 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: reset my form to its original state

Posted 02 February 2010 - 06:56 PM

Oh, that's easy peasy using C#. :)

myButton.Clear();
myCheckBox.Checked = false;



Figure out a way to iterate through your controls and you're all set. :)

Do something like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        public void reset()
        {
            foreach(Control x in this.Controls)
            {
                if (x is TextBox)
                {
                    ((TextBox)x).Clear();
                }                
            }

            foreach (Control y in this.Controls)
            {
                if (y is CheckBox)
                {
                    ((CheckBox)y).Checked = false;
                }               
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            reset();
        }
    }
}

This post has been edited by stapia.gutierrez: 02 February 2010 - 06:58 PM

Was This Post Helpful? 0
  • +
  • -

#5 cheeky01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-February 10

Re: reset my form to its original state

Posted 02 February 2010 - 06:56 PM

when a user selects a check box, the application removes check marks from any of the check boxes and clear the text boxes.
Was This Post Helpful? 0
  • +
  • -

#6 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: reset my form to its original state

Posted 02 February 2010 - 07:00 PM

Then call my Reset() method when a CheckedChanged event occurs.
Was This Post Helpful? 0
  • +
  • -

#7 cheeky01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-February 10

Re: reset my form to its original state

Posted 02 February 2010 - 07:01 PM

Error message says:

'System.Windows.Forms.Button' does not contain a definition for 'Clear'

An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.CheckBox.Checked.get'

 private void button2_Click(object sender, EventArgs e)
        {
            button2.Clear();
            CheckBox.Checked = false;


Was This Post Helpful? 0
  • +
  • -

#8 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: reset my form to its original state

Posted 02 February 2010 - 07:03 PM

That's because you cannot Clear() a button. :P

And you're getting an error in your CheckBox line, because you are calling on the big-daddy parent class of CheckBox, what you want to do is call on an instantiated CheckBox.
Was This Post Helpful? 0
  • +
  • -

#9 cheeky01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 02-February 10

Re: reset my form to its original state

Posted 03 February 2010 - 07:23 AM

what code would i use to reset check boxes when the user clicks a reset button?

This post has been edited by cheeky01: 03 February 2010 - 07:24 AM

Was This Post Helpful? 0
  • +
  • -

#10 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: reset my form to its original state

Posted 03 February 2010 - 07:26 AM

have you thought about changing the "Checked" property of the checkbox? You can set it to true or false to determine whether the checkbox is checked or not.

and a note to you, please make a title that is more descriptive of your problem. "C# Visual Studio 2005" does nothing to help other know what your problem is.

This post has been edited by eclipsed4utoo: 03 February 2010 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

#11 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: reset my form to its original state

Posted 03 February 2010 - 08:06 AM

You already asked this, check out your previous thread:
http://www.dreaminco...ndpost&p=913679
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1