Reputation: 51
How would I save text in richTextBox1 and richTextBox2 into the same file, which could be accessed to use those text entries as strings to make labels? Is it possible to also save the state of a checkbox along with the text from the richTextBoxes?
Upvotes: 1
Views: 1516
Reputation: 609
Try this, this will save the values in a texfile
var strFilePathAndName = "anyPathAndFilename"
using (var fs = new System.IO.FileStream(strFilePathAndName, System.IO.FileMode.OpenOrCreate))
{
fs.Close();
}
// Create the writer for data.
using ( var w = new System.IO.StreamWriter(strFilePathAndName, true))
{
w.Write(richTextBox1.Text);
w.Write(richTextBox2.Text);
w.Write(checkBox1.Checked.toString());
w.Close();
}
Upvotes: 1
Reputation: 3483
"Is it possible to also save the state of a checkbox along with the text from the richTextBoxes?" I don't get it, but is that what you want ?
richtextBox1.text = IsItPossibleToSaveCheckboxState.Checked.ToString();
richTextBox1.text will show the check state like True -or- False
Upvotes: 0
Reputation: 1499790
You can save whatever you like in the file - you just need to work out what format you want to use. For example, you could use LINQ to XML:
var data = new XDocument("uistate",
new XElement("tb1", richTextBox1.Rtf),
new XElement("tb2", richTextBox2.Rtf),
new XElement("cb", checkBox.Checked));
data.Save("uistate.xml");
Upvotes: 4