我正在设计一个UserControl
将保存linklabel
s列表的。像这样的东西:
public class ItemControl : LinkLabel {}
public class ItemsControl : UserControl
{
private readonly List<ItemControl> items;
public TaskBox()
{
this.items = new List<ItemControl>();
}
public List<ItemControl> Items
{
get { return this.items; }
}
}
但是,UserControl
一旦将它们添加到列表中后,如何绘制它们呢?另外,如何在代码中向他们添加clicked事件?
您可以在FlowLayoutPanel
控件上放置控件,ItemsControl
并使用以下代码对其进行绘制ItemControl
:
foreach (var item in this.Items)
{
flowLayoutPanel1.Controls.Add(item);
item.LinkClicked += item_LinkClicked;
}
void item_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show(((item)sender).Name);
}
使用FlowLayaoutPanel
是任意的,但是如果您不使用FlowLayoutPanel
,则可以将它们LinkItem
直接放在上UserControl
,并且必须自己管理每个LinkItem
位置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句