0
我正在創建一個緊湊框架的菜單控件。該控件包含一系列項目。我可以使用Visual Studio設計器添加項目,但是,它們絕不會添加到設計器文件中,因此下次打開設計器或構建解決方案時,菜單不再有任何項目。緊湊框架自定義控件與集合不保存
下面是該項目的代碼:
public class Item
{
public int ImageIndex { get; set; }
private string _text = "";
public string Text
{
get { return _text ?? ""; }
set { _text = value ?? ""; }
}
public string Name { get; set; }
}
這裏是菜單中的相關代碼:
public class ItemMenu : Control
{
public ItemMenu()
{
Columns = 4;
RowHeight = 64;
ColumnWidth = 64;
_items.ListChanged += new ListChangedEventHandler(_items_ListChanged);
}
private BindingList<Item> _items = new BindingList<Item>();
public BindingList<Item> Items
{
get { return _items; }
}
public ImageList NormalImages { get; set; }
public ImageList SelectedImages { get; set; }
public int Columns { get; set; }
public int RowHeight { get; set; }
public int ColumnWidth { get; set; }
public int Rows
{
get { return (int)Math.Ceiling((double)Items.Count/(double)Columns); }
}
private void _items_ListChanged(object sender, ListChangedEventArgs e)
{
Refresh();
}
}
有誰知道我怎麼能得到項目保存到集合設計師文件,當我在視覺工作室設計師編輯?
我很困惑。在設計器文件中編輯時,不應輸入代碼。如果您輸入的是代碼,則不應該在「設計器生成的文件」中執行該操作。 – jp2code