[英]c# draw linklabel on usercontrol
我正在設計一個UserControl
,它將保存一個linklabel
的列表。 像這樣:
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
位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.