章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例
来源:互联网 发布:淘宝企业账号怎么注册 编辑:程序博客网 时间:2024/05/17 01:58
这篇文章讲述allowDrop属性的另一种用法,即接受文字,读者可以借鉴下,该文为转载文章地址:http://www.lob.cn/sl/control/431.shtml
RichTextBox.AllowDrop属性的实例
下面的代码示例演示如何使用 ListBox 控件(包含要放入 RichTextBox 控件的项)来执行拖放操作。窗体的构造函数将AllowDrop 属性设置为 true 以使拖放操作能够在 RichTextBox 中进行。该示例使用ListBox 的 MouseDown 事件通过调用 DoDragDrop 方法来启动拖动操作。该示例使用 DragEnter 事件来确定拖放到RichTextBox 中的项是否为有效的数据类型。DragDrop 事件将被拖动的项实际放在 RichTextBox 控件中RichTextBox 内的当前光标位置。该示例要求 DragDrop 和 DragEnter 事件已连接到此示例中定义的事件处理程序。
- Public Sub New()
- MyBase.New()
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
- richTextBox1.AllowDrop = True
- End Sub
- Private Sub listBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles listBox1.MouseDown
- ' Determines which item was selected.
- Dim lb As ListBox = CType(sender, ListBox)
- Dim pt As New Point(e.X, e.Y)
- 'Retrieve the item at the specified location within the ListBox.
- Dim index As Integer = lb.IndexFromPoint(pt)
- ' Starts a drag-and-drop operation.
- If index >= 0 Then
- ' Retrieve the selected item text to drag into the RichTextBox.
- lb.DoDragDrop(lb.Items(index).ToString(), DragDropEffects.Copy)
- End If
- End Sub 'listBox1_MouseDown
- Private Sub richTextBox1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles richTextBox1.DragEnter
- ' If the data is text, copy the data to the RichTextBox control.
- If e.Data.GetDataPresent("Text") Then
- e.Effect = DragDropEffects.Copy
- End If
- End Sub 'richTextBox1_DragEnter
- Private Sub richTextBox1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles richTextBox1.DragDrop
- ' Paste the text into the RichTextBox where at selection location.
- richTextBox1.SelectedText = e.Data.GetData("System.String", True).ToString()
- End Sub 'richTextBox1_DragDrop
0 0
- 章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例
- 章鱼哥—VB.NET 控件中你不知道的属性之——AllowDrop 应用详解
- VB.NET 章鱼哥 如何修改一个项目的名称
- VB.NET 章鱼哥 自定义控件的建立和使用
- 章鱼哥出品——VB.NET 屏幕自适应功能的实现
- VB.NET 章鱼哥出品 —入门基础Button控件的使用详解(二)
- [VB.NET]关于RichtextBox的DetectUrls属性和LinkClicked事件
- VB.NET章鱼哥出品—如何解决MDI子窗体被父窗体中的控件覆盖的问题
- VB.NET 章鱼哥出品--入门基础Button控件的使用详解(一)
- VB.NET 章鱼哥 编程实现获取图片上任一点的RGB值
- 章鱼哥 VB.NET 给自定义的过程函数添加中文说明
- VB.NET 章鱼哥 ——程序员也懂爱,动态绘制红心,很浪漫哦
- 章鱼哥—VB.NET 如何实现代码自动生成控件 添加绑定事件
- 章鱼哥出品—VB.NET 自定义快捷键使用详解之全局热键
- 章鱼哥出品—VB.Net 自定义快捷键详解之半全局快捷键
- 章鱼哥出品—VB.NET Office操作之Word(一)
- 章鱼哥出品—VB.NET Office操作之Word(二)
- 章鱼哥出品—VB.NET 如何绘制圆角矩形,并适应窗体大小
- Symmetric Tree
- C/C++ char和int的区别
- 章鱼哥—VB.NET 控件中你不知道的属性之——AllowDrop 应用详解
- 输入外挂
- C#添加Tao控件来调用opengl
- 章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例
- 二叉树中节点的最大距离(树的最长路径)——递归解法
- Convert Sorted Array to Binary Search Tree
- ggggggggggggggggg
- ggggggggggggggggggggg
- Remove Duplicates from Sorted Array
- Implement strStr()
- 用户体验的一些相关看法
- 网站改版如何处理避免被降权