private void list2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (list2.IndexFromPoint(e.X, e.Y) < 0) //>list2.Items.Count){ { return; } UserQueryCur = UserQueries.List[list2.IndexFromPoint(e.X, e.Y)]; textQuery.Text = UserQueryCur.QueryText; textTitle.Text = UserQueryCur.Description; textFileName.Text = UserQueryCur.FileName; }
private void listCategory_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { listCategory.SelectedIndex = listCategory.IndexFromPoint(e.X, e.Y); //test for -1 only necessary if there is whitespace, which there is not. SelectedCat = (int)lookupCat[listCategory.SelectedIndex]; FillCats(); }
public void GetPlaceMenu(System.Windows.Forms.ListBox listbox, MouseEventArgs e) { int index = listbox.IndexFromPoint(e.Location); if (index != System.Windows.Forms.ListBox.NoMatches) { var item = (Place)listbox.Items[index]; if (ActiveUser.Text != "Войдите в систему") { var pm = new PlaceMenu(user) { Place = item }; pm.Show(); } else { var pm = new PlaceMenu() { Place = item }; pm.Show(); } } }
private void lbData_MouseMove(object sender, MouseEventArgs e) { Point p = new Point(e.X, e.Y); int index = lbData.IndexFromPoint(p); if (index >= 0) { lbData.SelectedIndex = index; } }
static void toolboxControl_DragDrop(object sender, DragEventArgs e) { string data = null; if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText)) { data = e.Data.GetData(System.Windows.Forms.DataFormats.UnicodeText) as string; } if (e.Data.GetDataPresent(typeof(ScriptEditor).FullName + ".toolbox")) { object obj = e.Data.GetData(typeof(ScriptEditor).FullName + ".toolbox"); if (obj == toolboxControl) { if (data != null) { if (toolboxControl.Items.Contains(data)) { int id = toolboxControl.IndexFromPoint(toolboxControl.PointToClient(new Point(e.X, e.Y))); if (id < 0 || id >= toolboxControl.Items.Count) { id = toolboxControl.Items.Count - 1; } if ((string)toolboxControl.Items[id] == data) { return; } toolboxControl.Items.Remove(data); toolboxControl.Items.Insert(id, data); toolboxControl.SelectedItem = data; } else { toolboxControl.Items.Add(data); toolboxControl.SelectedItem = data; } } } else { if (data != null && !toolboxControl.Items.Contains(data)) { toolboxControl.Items.Add(data); toolboxControl.SelectedItem = data; } } } else if (data != null && !toolboxControl.Items.Contains(data)) { toolboxControl.Items.Add(data); toolboxControl.SelectedItem = data; } }
private void listBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { int idx = listBox.IndexFromPoint(e.X, e.Y); if (idx >= 0 && e.Button == MouseButtons.Right) { listBox.SelectedIndex = idx; } if (e.Button == MouseButtons.Right) { popUp.Show(listBox, new Point(e.X, e.Y)); } }
/// <summary> /// listbox's event handler for mousedown /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstWeatherItemNames_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { //if right click then select a record if (e.Button == MouseButtons.Right) { //given the point, return the item index Point pt = new Point(e.X, e.Y); int index = lstWeatherItemNames.IndexFromPoint(pt); if (index > 0) { //select the item pointed by the index lstWeatherItemNames.ClearSelected(); lstWeatherItemNames.SelectedIndex = index; lstWeatherItemNames.Refresh(); } } }
/// <summary> /// Event when the mouse is moved over a list. /// </summary> /// <param name="sender">Sender argument.</param> /// <param name="e">Event arguments.</param> private void List_MouseMove(object sender, MouseEventArgs e) { string toolTipText = string.Empty; System.Windows.Forms.ListBox list = (System.Windows.Forms.ListBox)sender; int index = list.IndexFromPoint(e.Location); if ((index >= 0) && (index < list.Items.Count)) { EntityItem item = (EntityItem)list.Items[index]; if (!string.IsNullOrWhiteSpace(item?.Parent?.GlobalName)) { toolTipText += $"Global optionset\t= {item.Parent.GlobalName}\r\n"; } if (!string.IsNullOrWhiteSpace(item?.GlobalName)) { toolTipText += $"Global optionset\t= {item.GlobalName}\r\n"; } toolTipText += $"Disaplay Name\t= {item.DisplayName}\r\n"; if (item.Value == 0) { toolTipText += $"Logical Name\t= {item.LogicalName}\r\n"; } else { toolTipText += $"Description\t= {item?.Description?.LocalizedLabels.Where(l => l.LanguageCode == DefaultLanguage).FirstOrDefault()?.Label}\r\n"; toolTipText += $"Value\t\t= {item.Value}"; } if (this.toolTip.GetToolTip(list) != toolTipText) { toolTip.SetToolTip(list, toolTipText); } } }
private void ListDragSource_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { // Get the index of the item the mouse is below. indexOfItemUnderMouseToDrag = ListDragSource.IndexFromPoint(e.X, e.Y); if (indexOfItemUnderMouseToDrag != ListBox.NoMatches) { // Remember the point where the mouse down occurred. The DragSize indicates // the size that the mouse can move before a drag event should be started. Size dragSize = SystemInformation.DragSize; // Create a rectangle using the DragSize, with the mouse position being // at the center of the rectangle. dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize); } else { // Reset the rectangle if the mouse is not over an item in the ListBox. dragBoxFromMouseDown = Rectangle.Empty; } }
private void detailList_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { ClearTimer(); hoverIndex = detailList.IndexFromPoint(e.X, e.Y); if (hoverIndex >= 0 && hoverIndex < detailList.Items.Count) { // Workaround problem of IndexFromPoint returning an // index when mouse is over bottom part of list. Rectangle r = detailList.GetItemRectangle(hoverIndex); if (e.Y > r.Bottom) { hoverIndex = -1; } else { hoverTimer = new System.Windows.Forms.Timer(); hoverTimer.Interval = 800; hoverTimer.Tick += new EventHandler(OnMouseHover); hoverTimer.Start(); } } }
private void ListDragTarget_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { // Determine whether string data exists in the drop data. If not, then // the drop effect reflects that the drop cannot occur. if (!e.Data.GetDataPresent(typeof(System.String))) { e.Effect = DragDropEffects.None; DropLocationLabel.Text = "None - no string data."; return; } // Set the effect based upon the KeyState. if ((e.KeyState & (8 + 32)) == (8 + 32) && (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) { // KeyState 8 + 32 = CTL + ALT // Link drag-and-drop effect. e.Effect = DragDropEffects.Link; } else if ((e.KeyState & 32) == 32 && (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) { // ALT KeyState for link. e.Effect = DragDropEffects.Link; } else if ((e.KeyState & 4) == 4 && (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { // SHIFT KeyState for move. e.Effect = DragDropEffects.Move; } else if ((e.KeyState & 8) == 8 && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) { // CTL KeyState for copy. e.Effect = DragDropEffects.Copy; } else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { // By default, the drop action should be move, if allowed. e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } // Get the index of the item the mouse is below. // The mouse locations are relative to the screen, so they must be // converted to client coordinates. indexOfItemUnderMouseToDrop = ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y))); // Updates the label text. if (indexOfItemUnderMouseToDrop != ListBox.NoMatches) { DropLocationLabel.Text = "Drops before item #" + (indexOfItemUnderMouseToDrop + 1); } else { DropLocationLabel.Text = "Drops at the end."; } }
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; }
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; } } }
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; }
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(); }