Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C语言中保存富文本框的背景色_C#_Asp.net_Textbox_Load_Save - Fatal编程技术网

C# 在C语言中保存富文本框的背景色

C# 在C语言中保存富文本框的背景色,c#,asp.net,textbox,load,save,C#,Asp.net,Textbox,Load,Save,目前,我正在将rich textbox的内容保存为: private void asRTFToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFile1 = new SaveFileDialog(); saveFile1.DefaultExt = "*.rtf"; saveFile1.Filter = "RTF Fi

目前,我正在将rich textbox的内容保存为:

private void asRTFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile1 = new SaveFileDialog();
            saveFile1.DefaultExt = "*.rtf";
            saveFile1.Filter = "RTF Files|*.rtf|TXT Files|*.txt";
            if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
               saveFile1.FileName.Length > 0)
            {
                telep.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText);
            }
        }
并将其加载为:

private void rTFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile1 = new OpenFileDialog();
            openFile1.DefaultExt = "*.rtf";
            openFile1.Filter = "RTF Files|*.rtf";
            if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
               openFile1.FileName.Length > 0)
            {
                telep.LoadFile(openFile1.FileName, RichTextBoxStreamType.RichText);
            }
        }
如何保存和加载rich textbox的背景色?

尝试使用Registry

`private void SaveSettings()
{
        RegistryKey R = Registry.CurrentUser.CreateSubKey("RTF box");
        R.SetValue("FontName", textBox1.Font.FontFamily.GetName(0));
        R.SetValue("FontSize", Convert.ToString(textBox1.Font.Size));
        R.SetValue("ForeCol", Convert.ToString(textBox1.ForeColor.ToArgb()));
        R.SetValue("BackCol", Convert.ToString(textBox1.BackColor.ToArgb()));
        R.SetValue("WordWrap", Convert.ToString(textBox1.WordWrap));

}`

使用富文本框的函数来代替文本框

,那么如何将其放入RTF文件中。我不想使用注册表。我希望能够使用该对话框访问文件。富文本框保存文本颜色/font/etc。对于富文本框,我也希望能够保存它的背景色。有什么想法吗?很抱歉,我忘记了这个问题,但是RTF文档每段文本都有自己的颜色、字体和大小,因此您无法保存它们。背景颜色可以通过上述相同的方法保存,但将textbox函数替换为richtextbox函数