文本编辑器问题 [英] Text editor problem

查看:121
本文介绍了文本编辑器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计自己的文本编辑器但是我有点问题。



我想要做的就是当你双击我的程序打开的txt文件,但没有显示任何文字。



我在网上搜索但我找到的并不是完整的代码,我可以在我的文本编辑器中使用。



请帮助。

问候

Hi I''m designing my own text editor but i''m having bit of a problem.

what I''m trying to do is when you double click on the txt file my program opens up but does not display any text.

I have search the web but all I found is not complete code that I can use in my text editor.

please help.
regards

推荐答案

在TXTEditor类中定义两个构造函数



例如:
Define two constructor in your TXTEditor class

eg:
//which is generated by default
public TXTEditor()
{
InitializeComponent();
}

//new Contructor
public TXTEditor(string fileName)
{
//your code goes here
}


谢谢你帮助解决了问题Jibesh



Thank you helped solve the problem Jibesh

public Form1()
       {
           InitializeComponent();
       }
       public Form1(string filename)
       {
           InitializeComponent();

           if (filename != null)
           {
               try
               {
                   //textBox1.LoadFile(filename); remove this line
                   StreamReader reader = new StreamReader(filename);
                   char[] data = new char[filename.Length];
                   reader.ReadBlock(data, 0, (int)filename.Length);
                   textBox1.Text = new string(data);
                   reader.Close();// and add these lines
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
           }
}


这篇关于文本编辑器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆