首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

textbox 设置文字格式的保存有关问题

2012-06-28 
textbox 设置文字格式的保存问题我想在我的程序中的有一个textbox我想通过FontDialog 对话框来设置textbox

textbox 设置文字格式的保存问题
我想在我的程序中的有一个 textbox 我想通过 FontDialog 对话框来设置 textbox 的文字的格式,我想把设置的文字的格式的信息存入到一个 配置文件当中 如: aa.dll 中,当窗体启动的时候,我想通过读取 配置文件中的数据来使 textbox 的字体的格式为设置的格式,我不知道怎么去实现。

我已经实现了保存字体的颜色的功能 就是保存 Font.Color.R G B 来实现的

我的意思就是想实现跟这个差不多的功能 但是我不知道用哪些属性和方法来实现

[解决办法]
就用三楼的代码

C# code
         private void button1_Click(object sender, EventArgs e)         {            //打开FontDialog 选择字体样式并保存             FontDialog fd = new FontDialog();            fd.ShowColor = true;            if (fd.ShowDialog() == DialogResult.OK)            {                object[] obj = new object[] { fd.Font, fd.Color };                BinaryFormatter formatter = new BinaryFormatter();                using (FileStream stream = File.Open("aa.dll", FileMode.Create))                {                    formatter.Serialize(stream, obj);                }            }                    }        private void button2_Click(object sender, EventArgs e)        {            object[] obj;            BinaryFormatter formatter = new BinaryFormatter();            using (FileStream stream = File.Open("aa.dll", FileMode.Open))            {                obj = (object[])formatter.Deserialize(stream);            }            Font font = (Font)obj[0];            Color color = (Color)obj[1];            //读取保存的字体样式信息并设置            this.textBox1.Font = font;            this.textBox1.ForeColor = color;                   }
[解决办法]
formload 事件读取处加上判断
C# code
youPath1 = Application.StartupPath + @"\\文字格式.dll";if (File.Exists(youPath1)){    object[] obj;    BinaryFormatter formatter = new BinaryFormatter();    using (FileStream stream = File.Open(youPath1, FileMode.Open))    {        obj = (object[])formatter.Deserialize(stream);    }    Font font = (Font)obj[0];    Color color = (Color)obj[1];    txt1.Font = font;} 

热点排行