C#richTextBox的一个保存问题
实例化的richTextBox 不能存储内容吗??
控件:
richTextBox1 comboBox1 button1
把下面的 public static void BindCom(RichTextBox txt,ComboBox com, string path)
改为
public static void BindCom(ComboBox com, string path)
去掉注释
//RichTextBox txt = new RichTextBox(); ← 注意这实例化
这样的话,保存内容是什么都没有,断点后看了一下,明明有内容的,却为何保存不了呢?求解惑!!!
控件:
richTextBox1 comboBox1 button1
把下面的 public static void BindCom(RichTextBox txt,ComboBox com, string path)
改为
public static void BindCom(ComboBox com, string path)
去掉注释
//RichTextBox txt = new RichTextBox(); ← 注意这实例化
这样的话,保存内容是什么都没有,断点后看了一下,明明有内容的,却为何保存不了呢?求解惑!!!
//绑定下拉框数据
public static void BindCom(RichTextBox txt,ComboBox com, string path)
{
//RichTextBox txt = new RichTextBox(); ← 注意这实例化
string[] typeBooks;
if (!File.Exists(path))
{
typeBooks = new string[]{"选择类型","type0","type1",
"type2","type3","type4","type5","type6"};
int count = typeBooks.Count();
int len = 1;
foreach (var str in typeBooks)
{
txt.Text += str;
if (len < typeBooks.Count())
{ txt.Text += "\n"; len++; }
}
txt.SaveFile(path, RichTextBoxStreamType.PlainText);
}
FileStream fs = new FileStream(path,
FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs, Encoding.Default);
txt.Text = sr.ReadToEnd();
sr.Close();
sr.Dispose();
typeBooks = txt.Lines;
foreach (var str in typeBooks)
{
if (str != "")
com.Items.Add(str);
}
com.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
//typeBooks = new string[]{"选择类型","type0","type1",
// "type2","type3","type4","type5","type6"};
//int count = typeBooks.Count();
//int len = 1;
//foreach (var str in typeBooks)
//{
// richTextBox1.Text += str;
// if (len < typeBooks.Count())
// { richTextBox1.Text += "\n"; len++; }
//}
//richTextBox1.SaveFile("Type.txt", RichTextBoxStreamType.TextTextOleObjs);
BindCom(richTextBox1 ,comboBox1, "Type.txt");
}
...全文
相关推荐
C#richTextBox显示和保存带格式的Word文档
C#实现richTextBox显示、保存和另存为带格式的Word文档
CSHARP_RichTextBoxEditor_c#RichTextBox_
c# sample ritchtextobox.
C#RichTextBox 行号 与同步滚动
实现了RichTextBox行号、同步滚动、字体大小设置不影响行号 高亮显示与智能提示后续提供...
【原创】实现richtextbox 查找 替换 查找下一个 全部替换 功能 源码
VB源码:实现 richtextbox 控件 查找 替换 查找下一个 全部替换 功能 源码,上传前自己调试通过,从自己的记事本提出来的,通过简单修改即可直接用于自己的程序
一个RichTextBox 自动加行号的程序
一个RichTextBox 自动加行号的程序,非常好用.


