I have a program in which i need to save the checked state of a menu strip item to a text file and have it load in when someone opens the file.
How do i find the bool of this and when i do how do i read it back in
i have attached a screen shot.
i would like the person to be able not only to save text data but also the boolean of the checked state of these buttons
Loading
FroglegPosted Jan 18, 2012, 1:47 AM
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;
using System.IO;// make sure you add this
namespace CheckedStateTxt
{
public partial class Form1 : Form
{
string checkValue;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loadTxtandState();
}
public void loadTxtandState()
{
if (File.Exists("txtInfo.txt"))
{
using (StreamReader sr = new StreamReader("txtInfo.txt"))
{
checkValue = sr.ReadLine();
if (checkValue == "true")
{
checkBox1.Checked = true;
}
else if (checkValue == "false")
{
checkBox1.Checked = false;
}
textBox1.Text = sr.ReadLine();
}
}
}
private void bttnSave_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
checkValue = ("true");
}
else if (!checkBox1.Checked)
{
checkValue = ("false");
}
using (StreamWriter sw = new StreamWriter("txtInfo.txt"))
{
sw.WriteLine(checkValue);
sw.WriteLine(textBox1.Text);
}
}
}
}
Datta KharadPosted Jan 18, 2012, 1:24 AM
Where is attached a screen shot?