本文整理汇总了C#中System.Windows.Forms.ListBox.IndexFromPoint方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.IndexFromPoint方法的具体用法?C# ListBox.IndexFromPoint怎么用?C# ListBox.IndexFromPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListBox
的用法示例。
在下文中一共展示了ListBox.IndexFromPoint方法的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();
}