一、实现的效果是,当点击一个按钮时,打开“打开文件”对话框,然后选中一个HTML文件点“打开”后
在文本框中显示出来当前打开文件的HTML源代码!!  30分
二、(问题如上)但实现不用打开,直接用拖拽文件到文本框中并且显示HTML源代码!!  40分

解决方案 »

  1.   

    textBox1.Text = yourStreamReader.ReadToEnd();
      

  2.   

            private string ReadFile(string file)
            {
                System.IO.TextReader txt = new System.IO.StreamReader(file);
                string s= txt.ReadToEnd();
                txt.Close();
                return s;
            }        private void textBox1_DragEnter(object sender, DragEventArgs e)
            {
                 if (e.Data.GetDataPresent(DataFormats.FileDrop) )
                 {
                     e.Effect = DragDropEffects.All;
                 }
            }        private void textBox1_DragDrop(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    string[] MyFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                    string strText = "";
                    for (int i = 0; i < MyFiles.Length; i++)
                    {
                        strText += ReadFile(MyFiles[i]);
                    }                textBox1.Text = strText;
                }
            }        private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.AllowDrop = true;
                textBox1.Multiline = true;
            }