用C#设计了一个按键,打开.rtf和.txt文件,但是为什么只能打开.txt文件,打开.rtf文件会报错
代码如下:privatevoidbutton1_Click(objectsender,EventArgse){openFileDialog1.FileName="";op...
代码如下:
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "RTF FILE(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
switch (openFileDialog1.FilterIndex)
{
case 1:
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
break;
case 2:
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
break;
}
} 展开
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "RTF FILE(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
switch (openFileDialog1.FilterIndex)
{
case 1:
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
break;
case 2:
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
break;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |