public class MyListBox:ListBox
{
private static readonly object EventItemClick = new object()
public event EventHandler<ListBoxItemEventArgs>ItemClick
{
add
{
Events.AddHandler(EventItemClick, value)
}
remove
{
Events.RemoveHandler(EventItemClick, value)
}
}
protected virtual void OnItemClick(ListBoxItemEventArgs e)
{
EventHandler<ListBoxItemEventArgs>handler = (EventHandler<ListBoxItemEventArgs>)this.Events[EventItemClick]
if (handler != null)
{
handler(this, e)
}
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e)
for (int i = 0i <this.Items.Counti++)
{
bool flag = this.GetItemRectangle(i).Contains(this.PointToClient(Control.MousePosition))
if (flag)
{
ListBoxItemEventArgs args = new ListBoxItemEventArgs(i)
OnItemClick(args)
break
}
}
}
}
public class ListBoxItemEventArgs : EventArgs
{
private int _listBoxItem
public ListBoxItemEventArgs(int listBoxItem)
{
_listBoxItem = listBoxItem
}
public int ListBoxItem
{
get
{
return _listBoxItem
}
}
}
没没看懂是什么意思呢,申明一个全局的
Hashtable st=new Hashtable()
添加的时候
listbox1.items. add(“链接一”);
st. add("链接一",socket)
用的时候
socket soc =st[item.to string] as S
ocket
,注意,st添加的时候要判断是否已包含了键哈,如果包含了用等号,不能用add了,同时还ListBox中元素变化的时候,st要和他同步才可以哈,手机回答的,忘采纳
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)