有没有一个变量是可以在关闭后再打开不会初始化的? 有没有一个变量是可以在关闭后依旧不会更改的?比如form窗体里有个textbox1,当第一次用户打开后,输入“abcdefg”,然后点button1进行“保存”。然后关闭程序,再次打开后,点击button2(或不需要点击)就直接在textbox1显示上次输入的文字“abcdefg”? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 拿个最简单的。每打开1次 StatusStrip1的label1会显示:“您已使用X次”……这个X变量要怎么设置? 一般写到文本文件(后缀.ini)或者xml文件中 建议使用ini文件,并使用你的程序的guid值进行数据移位;如果又想不给人家那末容易该的话,可以从多方面来记录,到时候比较一下是否一致就行啦,不过会比较麻烦 给你一个序列化的代码,假设你界面有个文本框一个按钮在窗体加载的函数里写 private void Form6_Load(object sender, EventArgs e) { if (System.IO.File.Exists(Application.StartupPath + "num.dat")) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.FileStream fs = new System.IO.FileStream(Application.StartupPath + "num.dat", System.IO.FileMode.Open); this.textBox1.Text = formatter.Deserialize(fs).ToString(); fs.Close(); } else this.textBox1.Text = "0"; }在点击按钮保存textbox的值的函数里写private void button2_Click(object sender, EventArgs e) { string num = this.textBox1.Text; System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.FileStream fs = new System.IO.FileStream(Application.StartupPath + "num.dat", System.IO.FileMode.Create); formatter.Serialize(fs, num); fs.Close(); }num.dat就是一个2进制文件 关于数组的问题请教下! c# 操作access错在那里? C#监听问题 关于excel报表中如何设置图片的大小 给介绍一本c#入门书啊。。。 如何在自定义控件的属性中(设计阶段)列举当前页上指定类型的控件id? 如何让checkbox选中时不显勾,而显示叉 各位港我看看这个错误?? 如何编写停靠窗口,有源码更好. 请指导,谢谢 在WinForm里输入矩阵,有没有什么好的思路呢? c#中如何将存在内存中的RGB序列 转换为Bitmap
每打开1次 StatusStrip1的label1会显示:“您已使用X次”……
这个X变量要怎么设置?
在窗体加载的函数里写
private void Form6_Load(object sender, EventArgs e)
{
if (System.IO.File.Exists(Application.StartupPath + "num.dat"))
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.FileStream fs = new System.IO.FileStream(Application.StartupPath + "num.dat", System.IO.FileMode.Open);
this.textBox1.Text = formatter.Deserialize(fs).ToString();
fs.Close();
}
else
this.textBox1.Text = "0";
}
在点击按钮保存textbox的值的函数里写
private void button2_Click(object sender, EventArgs e)
{
string num = this.textBox1.Text;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.FileStream fs = new System.IO.FileStream(Application.StartupPath + "num.dat", System.IO.FileMode.Create);
formatter.Serialize(fs, num);
fs.Close();
}
num.dat就是一个2进制文件