本文整理汇总了C#中System.Windows.Forms.ListBox.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.Dispose方法的具体用法?C# ListBox.Dispose怎么用?C# ListBox.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ListBox
的用法示例。
在下文中一共展示了ListBox.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _CreateListBox
private void _CreateListBox(string filter)
{
if (_listBox != null)
{
_listBox = null;
return;
}
if (!_listBoxOpened)
{
_listBox = new ListBox();
//listBox.scrollDirection = 1;
//listBox.ItemWidth = Width;
//listBox.ItemHeight = 20;
_listBox.FixedHeight = true;
_listBox.Font = Font;
_listBox.BringToFront();
_listBox.Context = true;
_listBox.Width = Width;
_listBox.Height = _listBox.ItemHeight * (Items.Count > MaxDropDownItems ? MaxDropDownItems : Items.Count);
if (_listBox.Height < _listBox.ItemHeight) _listBox.Height = _listBox.ItemHeight;
bool selectedIndexChanged = false;
for (int i = 0; i < Items.Count; i++)
{
var item = Items[i];
if (DropDownStyle == ComboBoxStyle.DropDownList || String.IsNullOrEmpty(filter))
_listBox.Items.Add(item);
else
{
var itemString = item.ToString();
if (itemString.ToLower().Contains(filter.ToLower()))
{
_listBox.Items.Add(item);
if (itemString == filter)
{
_listBox.SelectedIndex = i;
selectedIndexChanged = true;
}
}
}
}
for (int i = 0; i < Items.Count; i++)
if (Items.IsDisabled(i))
{
_listBox.Items.Disable(i);
//Application.Log(i);
}
if (selectedIndexChanged == false)
{
if (SelectedIndex > -1)
_listBox.ScrollIndex = SelectedIndex;
_listBox.SelectedIndex = SelectedIndex;
}
var gpoint = PointToScreen(Point.Zero);
_listBox.Location = gpoint + new Point(0, Height);
_listBox.SelectedValueChanged += (object sender, EventArgs args) =>
{
if (_listBox != null)
{
for (int i = 0; i < Items.Count; i++)
if (Items[i] == _listBox.SelectedItem)
{
_filter = _listBox.SelectedItem.ToString();
SelectedItem = _listBox.SelectedItem;
break;
}
//SelectedIndex = _listBox.SelectedIndex;
_listBox.Dispose();
_listBox = null;
}
};
_listBox.OnDisposing += (object sender, EventArgs args) =>
{
var clientRect = new System.Drawing.Rectangle(0, 0, Width, Height);
var contains = clientRect.Contains(PointToClient(MousePosition));
if (!contains)
_listBoxOpened = false;
else
_listBoxOpened = !_listBoxOpened;
_listBox = null;
};
}
else
_listBoxOpened = false;
}