这篇文章讲述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 事件已连接到此示例中定义的事件处理程序。
- PublicSubNew()
- MyBase.New()
-
-
- InitializeComponent()
-
- richTextBox1.AllowDrop=True
-
- EndSub
-
- PrivateSublistBox1_MouseDown(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandleslistBox1.MouseDown
-
- DimlbAsListBox=CType(sender,ListBox)
- DimptAsNewPoint(e.X,e.Y)
-
- DimindexAsInteger=lb.IndexFromPoint(pt)
-
-
- Ifindex>=0Then
-
- lb.DoDragDrop(lb.Items(index).ToString(),DragDropEffects.copy)
- EndIf
- EndSub
-
-
- PrivateSubrichTextBox1_dragenter(ByValsenderAsObject,ByValeAsDragEventArgs)HandlesrichTextBox1.dragenter
-
- Ife.Data.GetDataPresent("Text")Then
- e.Effect=DragDropEffects.copy
- EndIf
- EndSub
-
- PrivateSubrichTextBox1_DragDrop(ByValsenderAsObject,ByValeAsDragEventArgs)HandlesrichTextBox1.DragDrop
-
- richTextBox1.SelectedText=e.Data.GetData("System.String",True).ToString()
- EndSub
|
原文地址:https://www.jb51.cc/vb/257773.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。