How to save form elements propeties?
Hi, I want to know how to save elements properties even after the form closes, and resume it back when I open the form.
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void apply_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
MessageBox.Show("Checkbox1 is checked");
}
else if (checkBox2.Checked == true)
{
MessageBox.Show("Checkbox2 is checked");
}
else
{
MessageBox.Show("Checkbox3 is checked");
}
}
private void load_Click(object sender, EventArgs e)
{
}
private void save_Click(object sender, EventArgs e)
{
}
}
}
Suppose I check the checkbox2 and click apply button, it should save and close.
When I open back the form then the checkbox2 should be checked.
And also if I have checked checkbox3 and click save button it should save the settings and by clicking on load button it should load back(i.e checkbox3 should be checked)
p.s how to save the setting data?
Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
You could store your settings in the application resources and read them back in.
You could do some Serialization.
One question : check your if statement. What if all 3 checkboxes are checked?
If that is not the behaviour you want, use radiobuttons instead.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Thanks skatamatic this works perfectly!
But what if my form contains checkbox, radio button, slider, combobox etc.
Its not loading!
how to do that?
Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
I m not able to load settings!
i.e checkbox should get ticked
Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Got it! I did some mistake! Thanks..
If I'll face any difficulty/problem I'll pm you!
Thanks once again skatamatic!
Solved!
Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
@ddanbe
Thankyou for the link!
Andy90
Junior Poster in Training
73 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0