c#问题,高手进

来源:百度知道 编辑:UC知道 时间:2024/05/19 10:53:27
我刚做了一个记事本。这么实现这种功能:
把一个已经做好的.TXT文件,拖到我的记事本应用程序上,记事本能打开TXT的内容。
需要在C#里写代码实现吗?怎么写?
好象就是拖放打开。TXT文件问题。代码怎么写?

这是一点参考代码,你看看,不过打开的中文是乱码,这点我还没办法解决……:
private void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] fileName;
// FileNameW是Unicode,用于东亚文字,如果是其它地区的文字,可用FileName
fileName = e.Data.GetData("FileNameW") as string[];
if (fileName != null && fileName.Length > 0)
{
StreamReader sr = File.OpenText(fileName[0]);
richTextBox1.Text = sr.ReadToEnd();
}
}
else
{
e.Effect = DragDropEffects.None;
}
}

private void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;<