加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例

发布时间:2020-12-17 07:51:54 所属栏目:百科 来源:网络整理
导读:这篇文章讲述allowDrop属性的另一种用法,即接受文字,读者可以借鉴下,该文为转载文章地址:http://www.lob.cn/sl/control/431.shtml RichTextBox.AllowDrop属性的实例 下面的代码示例演示如何使用 ListBox 控件(包含要放入 RichTextBox 控件的项)来执行

这篇文章讲述allowDrop属性的另一种用法,即接受文字,读者可以借鉴下,该文为转载文章地址:http://www.lob.cn/sl/control/431.shtml


RichTextBox.AllowDrop属性的实例

下面的代码示例演示如何使用 ListBox 控件(包含要放入 RichTextBox 控件的项)来执行拖放操作。窗体的构造函数将 AllowDrop 属性设置为 true 以使拖放操作能够在 RichTextBox 中进行。该示例使用 ListBox 的 MouseDown 事件通过调用 DoDragDrop 方法来启动拖动操作。该示例使用 DragEnter 事件来确定拖放到 RichTextBox 中的项是否为有效的数据类型。DragDrop 事件将被拖动的项实际放在 RichTextBox 控件中 RichTextBox 内的当前光标位置。该示例要求 DragDropDragEnter 事件已连接到此示例中定义的事件处理程序。

  1. PublicSubNew()
  2. MyBase.New()
  3. 'ThiscallisrequiredbytheWindowsFormDesigner.
  4. InitializeComponent()
  5. richTextBox1.AllowDrop=True
  6. EndSub
  7. PrivateSublistBox1_MouseDown(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandleslistBox1.MouseDown
  8. 'Determineswhichitemwasselected.
  9. DimlbAsListBox=CType(sender,ListBox)
  10. DimptAsNewPoint(e.X,e.Y)
  11. 'RetrievetheitematthespecifiedlocationwithintheListBox.
  12. DimindexAsInteger=lb.IndexFromPoint(pt)
  13. 'Startsadrag-and-dropoperation.
  14. Ifindex>=0Then
  15. 'RetrievetheselecteditemtexttodragintotheRichTextBox.
  16. lb.DoDragDrop(lb.Items(index).ToString(),DragDropEffects.Copy)
  17. EndIf
  18. EndSub'listBox1_MouseDown
  19. PrivateSubrichTextBox1_DragEnter(ByValsenderAsObject,ByValeAsDragEventArgs)HandlesrichTextBox1.DragEnter
  20. 'Ifthedataistext,copythedatatotheRichTextBoxcontrol.
  21. Ife.Data.GetDataPresent("Text")Then
  22. e.Effect=DragDropEffects.Copy
  23. EndIf
  24. EndSub'richTextBox1_DragEnter
  25. PrivateSubrichTextBox1_DragDrop(ByValsenderAsObject,ByValeAsDragEventArgs)HandlesrichTextBox1.DragDrop
  26. 'PastethetextintotheRichTextBoxwhereatselectionlocation.
  27. richTextBox1.SelectedText=e.Data.GetData("System.String",True).ToString()
  28. EndSub'richTextBox1_DragDrop

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读