[C#]richtextbox实现拖放

简介: namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); richTextBox1.
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            richTextBox1.AllowDrop = true;
            richTextBox1.DragEnter += new DragEventHandler(richTextBox1_DragEnter);
            richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
        }

        private void richTextBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Link;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void richTextBox1_DragDrop(object sender, DragEventArgs e)
        {
            Array arrayFileName = (Array)e.Data.GetData(DataFormats.FileDrop);

            string strFileName = arrayFileName.GetValue(0).ToString();

            StreamReader sr = new StreamReader(strFileName,System.Text.Encoding.Default);
            richTextBox1.Text = sr.ReadToEnd();
            sr.Close();
        }
    }
}
目录
相关文章
|
C# 数据库
C# 让RichTextBox支持GIF
我只是做了一些简单的测试...有疑问给我发消息把. 使用方法 //获取选择的图形 并且保存出来 private void button2_Click(object sender, EventArgs e)    ...
974 0
|
C# 数据库 内存技术
C# 将RichTextBox中内容的文档以二进制形式存
private void button1_Click(object sender, EventArgs e)        {              System.IO.MemoryStream mstream = new System.
898 0
|
C#
C#Winform使用扩展方法自定义富文本框(RichTextBox)字体颜色
在利用C#开发Winform应用程序的时候,我们有可能使用RichTextBox来实现实时显示应用程序日志的功能,日志又分为:一般消息,警告提示 和错误等类别。为了更好地区分不同类型的日志,我们需要使用不同的颜色来输出对应的日志,比如:一般消息为绿色,警告提示的用橙色,错误的用红色字体。
1938 0
|
C# Windows
如何在C#下利用RichTextBox打开一个有文字格式和图片的Word文档
转自博客: http://blog.csdn.net/michellehsiao/article/details/7684309 小知识点:.Net Framework 4.0 和.Net Framework 4.0 Client Profile区别:       .NET Framework Client Profile是.NET Framework的裁剪版本。
1277 0
|
C# Windows
c# richTextBox显示一个txt文档出现中文乱码
1、参考解决方案 怎么读的呢? 如果是从文本中读的,考虑一下编码问题 FileStream fs = new FileStream(@"c:\你的文本.txt", FileMode.
2863 0
|
C# 移动开发
[C#]richtextbox实现行号
editorControl是一个userControl,其包含两个控件:左侧是一个用来显示行号的RichTextBox(使用label等均可),右侧是一个继承自RichTextBox的componenteditorGrid1。
911 0
|
1月前
|
C#
24. C# 编程:用户设定敌人初始血值的实现
24. C# 编程:用户设定敌人初始血值的实现
20 0