拖拽TXT文件到窗体并加载TXT文件
private void Form1_Load(object sender, EventArgs e)
{
this.AllowDrop=true;//设置MDI的父窗口的AllowDrop 属性更改为true;
}
//拖拽TXT文件到窗体并加载TXT文件
private void Form1_DragEnter(object sender, DragEventArgs e)
{
string file = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//获得路径
if (File.Exists(file))
{
string Extension = System.IO.Path.GetExtension(file).ToLower();
if (Extension == ".txt")
{
this.Text = System.IO.Path.GetFileName(file);
this.richTextBox1.LoadFile(file, RichTextBoxStreamType.PlainText);//读取txt文件
}
}
}