本文整理汇总了C#中System.Windows.Forms.ListBox.GetItemRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.GetItemRectangle方法的具体用法?C# ListBox.GetItemRectangle怎么用?C# ListBox.GetItemRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListBox
的用法示例。
在下文中一共展示了ListBox.GetItemRectangle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowTooltip
/// <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;
}
示例2: DrawItem
// 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();
}
示例3: GetCheckBoxRectangleForListBoxItem
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;
}
示例4: TipWindow
public TipWindow( ListBox listbox, int index )
{
InitializeComponent();
InitControl( listbox );
this.itemBounds = listbox.GetItemRectangle( index );
this.tipText = listbox.Items[ index ].ToString();
}
示例5: GetItemAt
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;
}
示例6: HandleListboxClick
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;
}