Jump to content

C# checkbox problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
yoda174

yoda174

    Newbie

  • Members
  • PipPip
  • 25 posts
Dear members!

I created a lanchat program. I want to make a settings section. I designed it in a new form that called settings and i put on the settings form one checkbox.With this checkbox I want to start in the main form one automatic logging timmer what log into one file the chat,i can start the autosave and it work fine:) but ever when close the settings form and i reopen the settings form the checkbox state is unchecked:cursing:,vainly checked it before closing and reopening:cursing:

my source code what check the autostart timer state on the form1 and "enable/disable" the checkbox
{

            InitializeComponent();

            Form1 form = new Form1();

            if (form.autosave.Enabled == true)

            {

                this.checkBox1.Checked = true;

                this.checkBox1.CheckState = CheckState.Checked;

            }

            else

            {

                this.checkBox1.Checked = false;

                this.checkBox1.CheckState = CheckState.Unchecked;

            }

        }

Any idea?

#2
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
Add a settings file to your project. Right-click on your project Add>>New Item>>Settings file. In that file add the settings you want, make sure they are user settings and not application settings.

Then, to edit those settings:
//Assuming we have a setting named autosave
//And out settings file is called Settings
ProjectName.Settings.Default.autosave = checkBox1.Checked.ToString();
ProjectName.Settings.Default.Save();
When you restart the application you will have the settings there.
I don't understand the rest of your question, can you please re-formulate?
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#3
yoda174

yoda174

    Newbie

  • Members
  • PipPip
  • 25 posts
I want start with the help of checkbox one timer on the form1 (it work),and when i close the setting and i reopen the settings i want to check that the autosave(this is the timer name) is running or not and if it's running i want that the checkbox will checked.(it doesn't work)

#4
tjcool

tjcool

    Newbie

  • Members
  • PipPip
  • 18 posts
plz simply it more or place code .........like u did above it help us more to understand u r problem ...

#5
yoda174

yoda174

    Newbie

  • Members
  • PipPip
  • 25 posts
I resolved this problem with Davide help:cool: I use Settings to check autosave state and it works fine thanx Davide:thumbup1: +rep

My source

InitializeComponent();

            if (Settings.Default.Enabled == true)

            {

                this.checkBox1.CheckState = CheckState.Checked;

            }

            else

            {

                this.checkBox1.CheckState = CheckState.Unchecked;

            }

            numericUpDown1.Value = Settings.Default.Interval;