本文整理汇总了C#中System.Windows.Forms.ListBox.IndexFromPoint方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.IndexFromPoint方法的具体用法?C# ListBox.IndexFromPoint怎么用?C# ListBox.IndexFromPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListBox
的用法示例。
在下文中一共展示了ListBox.IndexFromPoint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getIndex
private int getIndex(ListBox list, int x, int y)
{
Point point = list.PointToClient(new Point(x, y));
int index = list.IndexFromPoint(point);
if (index < 0) { index = list.Items.Count - 1; } //off the end of the list
return index;
}
示例2: OnHandleCreated
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
_dropDown = new ToolStripDropDown();
_box = new ListBox();
_box.Width = this.Width - 2;
_box.KeyDown += (KeyEventHandler)((sender, k) =>
{
if (k.KeyCode == Keys.Enter)
{
this.Text = _box.SelectedItem.ToString();
_dropDown.Close();
}
_dropDown.AutoClose = true;
if (k.KeyCode == Keys.Escape)
_dropDown.Close();
});
_box.Click += (EventHandler)((sender, arg) =>
{
this.Text = _box.SelectedItem.ToString();
_dropDown.Close();
});
_box.MouseMove += (MouseEventHandler)((sender, m) =>
{
int index = _box.IndexFromPoint(m.Location);
_box.SelectedIndex = index;
});
ToolStripControlHost host = new ToolStripControlHost(_box);
host.AutoSize = false;
host.Margin = Padding.Empty;
host.Padding = Padding.Empty;
_dropDown.Items.Add(host);
_dropDown.Height = _box.Height;
_dropDown.AutoSize = false;
_dropDown.Margin = Padding.Empty;
_dropDown.Padding = Padding.Empty;
_dropDown.Size = host.Size = _box.Size;
_dropDown.AutoClose = false;
}
示例3: listBox_MouseDown
private void listBox_MouseDown(object sender, MouseEventArgs e)
{
if (MouseButtons.Right == e.Button)
{
selectedListBox = (ListBox)sender;
int selectedIndex = selectedListBox.IndexFromPoint(e.X, e.Y);
selectedListBox.SelectedIndex = selectedIndex;
if (-1 == selectedIndex)
{
selectedListBox.ContextMenu = null;
}
else
{
selectedListBox.ContextMenuStrip = contextMenuListBox;
}
}
}
示例4: makeBulletDeleteForm
private void makeBulletDeleteForm()
{
Form f = new Form();
ListBox lb = new ListBox();
lb.MouseDoubleClick += (s, e) =>
{
int index = lb.IndexFromPoint(e.Location);
bullets.RemoveAt(index);
MessageBox.Show("Bullet" + (index + 1) + "deleted !", "Bullet Deletion", MessageBoxButtons.OK);
f.Close();
};
for (int i = 0; i < bullets.Count; i++)
{
lb.Items.Add("Bullet " + (i + 1));
}
f.Controls.Add(lb);
f.Size = new Size(300, 200);
lb.Width = f.Width;
f.Show();
}