本文整理汇总了C#中System.Windows.Forms.RichTextBox.AllowDrop属性的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.AllowDrop属性的具体用法?C# RichTextBox.AllowDrop怎么用?C# RichTextBox.AllowDrop使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.AllowDrop属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1
public Form1()
{
InitializeComponent();
// Sets the control to allow drops, and then adds the necessary event handlers.
this.richTextBox1.AllowDrop = true;
}
private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Determines which item was selected.
ListBox lb =( (ListBox)sender);
Point pt = new Point(e.X,e.Y);
//Retrieve the item at the specified location within the ListBox.
int index = lb.IndexFromPoint(pt);
// Starts a drag-and-drop operation.
if(index>=0)
{
// Retrieve the selected item text to drag into the RichTextBox.
lb.DoDragDrop(lb.Items[index].ToString(), DragDropEffects.Copy);
}
}
private void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
// If the data is text, copy the data to the RichTextBox control.
if(e.Data.GetDataPresent("Text"))
e.Effect = DragDropEffects.Copy;
}
private void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
// Paste the text into the RichTextBox where at selection location.
richTextBox1.SelectedText = e.Data.GetData("System.String", true).ToString();
}