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

章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例,第1张

概述这篇文章讲述allowDrop属性的另一种用法,即接受文字,读者可以借鉴下,该文为转载文章地址:http://www.lob.cn/sl/control/431.shtml RichTextBox.AllowDrop属性的实例   下面的代码示例演示如何使用 ListBox 控件(包含要放入 RichTextBox 控件的项)来执行拖放 *** 作。窗体的构造函数将 AllowDrop 属性设置为 tru

这篇文章讲述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() 'ThiscallisrequiredbythewindowsFormDesigner. InitializeComponent() richTextBox1.AllowDrop=True EndSub PrivateSubListBox1_MouseDown(ByValsenderAsObject,ByValeAsSystem.windows.Forms.MouseEventArgs)HandlesListBox1.MouseDown 'Determineswhichitemwasselected. DimlbAsListBox=CType(sender,ListBox) DimptAsNewPoint(e.X,e.Y) 'RetrIEvetheitematthespecifIEdlocationwithintheListBox. DimindexAsInteger=lb.IndexFromPoint(pt) 'Startsadrag-and-dropoperation. Ifindex>=0Then 'RetrIEvetheselecteditemtexttodragintotheRichTextBox. lb.DoDragDrop(lb.Items(index).ToString(),DragDropEffects.copy) EndIf EndSub'ListBox1_MouseDown PrivateSubrichTextBox1_dragenter(ByValsenderAsObject,ByValeAsDragEventArgs)HandlesrichTextBox1.dragenter 'Ifthedataistext,copythedatatotheRichTextBoxcontrol. Ife.Data.GetDataPresent("Text")Then e.Effect=DragDropEffects.copy EndIf EndSub'richTextBox1_dragenter PrivateSubrichTextBox1_DragDrop(ByValsenderAsObject,ByValeAsDragEventArgs)HandlesrichTextBox1.DragDrop 'PastethetextintotheRichTextBoxwhereatselectionlocation. richTextBox1.SelectedText=e.Data.GetData("System.String",True).ToString() EndSub'richTextBox1_DragDrop
总结

以上是内存溢出为你收集整理的章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例全部内容,希望文章能够帮你解决章鱼哥—VB.NET RichTextBox.AllowDrop属性的实例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1272342.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存