当前位置: 首页>>代码示例>>C#>>正文


C# ListBox.IndexFromPoint方法代码示例

本文整理汇总了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;
 }
开发者ID:brendan-w,项目名称:DDL-Creator,代码行数:7,代码来源:MainForm.cs

示例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;
 }
开发者ID:aelhadi,项目名称:opencbs,代码行数:39,代码来源:CityTextBox.cs

示例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;
                }
            }
        }
开发者ID:fedaykinofdune,项目名称:FishingForm,代码行数:19,代码来源:FishingForm.cs

示例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();
        }
开发者ID:amrufathy,项目名称:EscapeRunner,代码行数:23,代码来源:Menus.cs


注:本文中的System.Windows.Forms.ListBox.IndexFromPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。