本文整理汇总了C#中System.Windows.Forms.ToolStripDropDown.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripDropDown.Close方法的具体用法?C# ToolStripDropDown.Close怎么用?C# ToolStripDropDown.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripDropDown
的用法示例。
在下文中一共展示了ToolStripDropDown.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: OnHandleCreated
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
_dropDown = new ToolStripDropDown();
_box = new ListBox();
_box.Width = Width;
_box.Click += (sender, arg) =>
{ Text = _box.SelectedItem as string; _dropDown.Close(); };
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;
}
示例3: OnClick
public override bool OnClick(System.Windows.Forms.Control container, System.Windows.Forms.MouseEventArgs evnt, System.Drawing.Drawing2D.Matrix viewTransform)
{
base.OnClick(container, evnt, viewTransform);
if (evnt.Button == System.Windows.Forms.MouseButtons.Left)
{
var basePts = new PointF[] {
new PointF(Node.bounds.Left + GraphConstants.HorizontalSpacing, bounds.Top),
new PointF(Node.bounds.Right + GraphConstants.HorizontalSpacing - GraphConstants.NodeExtraWidth, bounds.Bottom) };
viewTransform.TransformPoints(basePts);
var dropDownCtrl = new ListBox();
dropDownCtrl.BorderStyle = BorderStyle.None;
dropDownCtrl.Margin = new Padding(0);
dropDownCtrl.Padding = new Padding(0);
dropDownCtrl.DrawMode = DrawMode.OwnerDrawVariable;
dropDownCtrl.DrawItem +=
(object sender, DrawItemEventArgs e) =>
{
var lb = sender as ListBox;
var item = lb.Items[e.Index];
bool selectedState = e.State != DrawItemState.None;
// We have to draw the background every item, because the control
// background isn't refreshed on state changes
e.Graphics.FillRectangle(selectedState ? Brushes.Gray : BackgroundBrush, e.Bounds);
e.Graphics.DrawString(
item.ToString(), SystemFonts.MenuFont, selectedState ? Brushes.Black : Brushes.White,
e.Bounds, GraphConstants.LeftTextStringFormat);
};
dropDownCtrl.MeasureItem +=
(object sender, MeasureItemEventArgs e) =>
{
var lb = sender as ListBox;
var item = lb.Items[e.Index];
var size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
var textSize = e.Graphics.MeasureString(
item.ToString(), SystemFonts.MenuFont,
size, GraphConstants.LeftMeasureTextStringFormat);
e.ItemWidth = (int)textSize.Width;
e.ItemHeight = (int)textSize.Height;
};
dropDownCtrl.BackColor = Color.FromArgb(96, 96, 96);
dropDownCtrl.Items.AddRange(Items);
dropDownCtrl.SelectedIndex = SelectedIndex;
var toolDrop = new ToolStripDropDown();
var toolHost = new ToolStripControlHost(dropDownCtrl);
toolHost.Margin = new Padding(0);
toolDrop.Padding = new Padding(0);
toolDrop.Items.Add(toolHost);
// Unfortunately the AutoSize functionality for toolHost just doesn't
// work with an owner draw list box... Perhaps MeasureItem isn't called
// until the list box is first drawn -- but that is after the tool host
// has done it's auto size
toolHost.AutoSize = false;
toolHost.Size = new Size((int)(basePts[1].X - basePts[0].X), dropDownCtrl.PreferredHeight + 20);
dropDownCtrl.SelectedIndexChanged +=
(object sender, System.EventArgs e) =>
{
var lb = sender as ListBox;
if (lb != null)
SelectedIndex = lb.SelectedIndex;
toolDrop.Close();
};
toolDrop.Show(container, new Point((int)basePts[0].X, (int)basePts[1].Y + 4));
return true;
}
return false;
}