public GetItemRectangle ( int index ) : |
||
index | int | |
return |
private void OnMouseHover(object sender, System.EventArgs e) { if (tipWindow != null) { tipWindow.Close(); } if (settings.GetSetting("Gui.ResultTabs.ErrorsTab.ToolTipsEnabled", false) && hoverIndex >= 0 && hoverIndex < detailList.Items.Count) { Graphics g = Graphics.FromHwnd(detailList.Handle); Rectangle itemRect = detailList.GetItemRectangle(hoverIndex); string text = detailList.Items[hoverIndex].ToString(); SizeF sizeNeeded = g.MeasureString(text, detailList.Font); bool expansionNeeded = itemRect.Width < (int)sizeNeeded.Width || itemRect.Height < (int)sizeNeeded.Height; if (expansionNeeded) { tipWindow = new TipWindow(detailList, hoverIndex); tipWindow.ItemBounds = itemRect; tipWindow.TipText = text; tipWindow.Expansion = TipWindow.ExpansionStyle.Both; tipWindow.Overlay = true; tipWindow.WantClicks = true; tipWindow.Closed += new EventHandler(tipWindow_Closed); tipWindow.Show(); } } }
private void lbSymbols_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { SymbolCollectionItem item = null; for (int i = 0; i < lbSymbols.Items.Count; i++) { Rectangle rect = lbSymbols.GetItemRectangle(i); if (rect.Y <= e.Y && (rect.Y + rect.Height) >= e.Y) { item = (SymbolCollectionItem)lbSymbols.Items[i]; break; } } if (item == null) { return; } _mouseDownItem = item; if (e.X < 20) { item.Visible = !item.Visible; DrawPreview(); } }
private Point getLinkLabelPoint(int index) { int linkLabelLeft; int linkLabelTop; if (this.listBox1.Size.Width < 475) { //this.listBox1. linkLabelLeft = 415; } else { linkLabelLeft = listBox1.Right - 85; } if (index >= 0 && listBox1.Items.Count > index) { linkLabelTop = listBox1.GetItemRectangle(index).Top + 5; } else { linkLabelTop = (80 * index) + 5; } return(new Point(linkLabelLeft, linkLabelTop)); }
/// <summary> /// Show a listbox with possible completions for the uncompleted string. /// When the user chooses one and presses enter (or clicks it with the mouse), /// return the chosen completion. Or, when the user presses escape, then /// close the window and return null. /// </summary> public string ShowTooltip(string uncompleted, IEnumerable<string> completions, IEnumerable<string> documentations,Point location) { _lstCompletions = new ListBox(); _lstCompletions.ScrollAlwaysVisible = true; _lstCompletions.Items.AddRange(completions.ToArray()); _lstCompletions.SelectionMode = SelectionMode.One; _lstCompletions.AutoSize = false; _lstCompletions.SelectedIndexChanged += new EventHandler(selectedIndexChanged); _lstCompletions.Click += new EventHandler(lstCompletionsClicked); int maxWidth = 0; for (int i = 0; i < _lstCompletions.Items.Count; i++) { if (_lstCompletions.GetItemRectangle(i).Width > maxWidth) maxWidth = _lstCompletions.GetItemRectangle(i).Width; } _lstCompletions.Width = maxWidth; if (_lstCompletions.Items.Count > 0) _lstCompletions.Height = _lstCompletions.GetItemHeight(0) * 10; _documentations = documentations; _lblDocumentation = new TextBox(); _lblDocumentation.WordWrap = true; _lblDocumentation.Width = _lstCompletions.Width; _lblDocumentation.BackColor = SystemColors.ControlLight; if (_documentations!=null && _documentations.Count() > 0) _lblDocumentation.Text = _documentations.ElementAt(0); _lblDocumentation.ScrollBars = ScrollBars.Vertical; _lblDocumentation.Multiline = true; _lblDocumentation.AutoSize = true; _lblDocumentation.Height = 100; _lblDocumentation.ReadOnly = true; _dialog = new CompletionToolTipWindow(_lstCompletions,_lblDocumentation); _dialog.KeyDown += new KeyEventHandler(dialog_KeyDown); _dialog.Location = location; _dialog.KeyPreview = true; _dialog.ShowDialog(); if (_cancel || _lstCompletions.SelectedIndex < 0) return null; return (string)_lstCompletions.SelectedItem; }
// For List Boxes -- TODO Need to make this work with prefereneces for UseCheckmark public static void DrawItem(this DrawItemEventArgs e, string text, Color color, ListBox lb, bool useCheckmark) { e.DrawBackground(); var selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected; GenericBrush.Color = color; e.Graphics.FillRectangle(selected && !useCheckmark ? SystemBrushes.Highlight : GenericBrush, e.Bounds); var contrastingBrush = selected && !useCheckmark ? SystemBrushes.HighlightText : color.GetTextColor(); e.Graphics.DrawString(text, e.Font, contrastingBrush, lb.GetItemRectangle(e.Index).Location); if (selected && useCheckmark) { e.Graphics.DrawString(Checkmark, e.Font, contrastingBrush, e.Bounds.Width - e.Bounds.Height, e.Bounds.Y); } e.DrawFocusRectangle(); }
private void CreateEditBox(object sender) { listBox1 = (ListBox)sender; itemSelected = listBox1.SelectedIndex; Rectangle r = listBox1.GetItemRectangle(itemSelected); string itemText = (string)listBox1.Items[itemSelected]; editBox.Location = new System.Drawing.Point(r.X, r.Y); editBox.Size = new System.Drawing.Size(r.Width, r.Height); editBox.Show(); listBox1.Controls.AddRange(new System.Windows.Forms.Control[] { this.editBox }); editBox.Text = itemText; editBox.Focus(); editBox.SelectAll(); editBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.EditOver); editBox.LostFocus += new System.EventHandler(this.FocusOver); }
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 listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { int n = listBox1.SelectedIndex; if (n >= 0) { listBox2.SelectedIndex = n; System.Drawing.Rectangle rc = listBox2.GetItemRectangle(n); cbxFK.SetBounds(rc.Left, rc.Top, rc.Width, rc.Height); EPField fld = listBox2.Items[n] as EPField; if (fld != null) { for (int i = 0; i < subTable.fields.Count; i++) { if (fld == subTable.fields[i]) { cbxFK.SelectedIndex = i; break; } } } cbxFK.Visible = true; } }
private Rectangle GetCheckBoxRectangleForListBoxItem(ListBox currentListBox, int itemIndex) { const int edgeMargin = 8; Rectangle itemRectangle = currentListBox.GetItemRectangle(itemIndex); // this is the bound of the checkbox var checkBoxRectangle = new Rectangle( itemRectangle.Left + edgeMargin + 2, itemRectangle.Top + edgeMargin, _checkBoxSize.Width, _checkBoxSize.Height); return checkBoxRectangle; }
public TipWindow( ListBox listbox, int index ) { InitializeComponent(); InitControl( listbox ); this.itemBounds = listbox.GetItemRectangle( index ); this.tipText = listbox.Items[ index ].ToString(); }
private int GetItemAt(ListBox listBox, int X, int Y) { int index = -1; for (int i = 0; i < listBox.Items.Count; i++) { System.Drawing.Rectangle r = listBox.GetItemRectangle(i); if (r.Contains(new Point(X, Y))) { index = i; break; } } return index; }
private int HandleListboxClick(ListBox lb, Rectangle clickloc) { for (var a = 0; a < lb.Items.Count; a++) { var a1 = lb.GetItemRectangle(a); var r = new Rectangle(lb.Location.X + a1.X, lb.Location.Y + a1.Y, a1.Width, a1.Height); if (r.Intersects(clickloc)) { lb.SelectedIndex = a; return a; } } lb.SelectedIndex = -1; return -1; }