如何在我自己的自定義Windows控件庫中實現小任務功能如下所示? C#中的自定義Windows控件庫
3
A
回答
3
您需要爲您的控件創建自己的設計器。通過添加對System.Design的引用開始。示例控件可能如下所示:
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
[Designer(typeof(MyControlDesigner))]
public class MyControl : Control {
public bool Prop { get; set; }
}
注意[Designer]屬性,它設置自定義控件設計器。爲了讓你開始,從ControlDesigner派生你自己的設計師。重寫ActionLists屬性創建任務列表爲設計師:
internal class MyControlDesigner : ControlDesigner {
private DesignerActionListCollection actionLists;
public override DesignerActionListCollection ActionLists {
get {
if (actionLists == null) {
actionLists = new DesignerActionListCollection();
actionLists.Add(new MyActionListItem(this));
}
return actionLists;
}
}
}
現在,您需要創建自定義ActionListItem,這可能是這樣的:
internal class MyActionListItem : DesignerActionList {
public MyActionListItem(ControlDesigner owner)
: base(owner.Component) {
}
public override DesignerActionItemCollection GetSortedActionItems() {
var items = new DesignerActionItemCollection();
items.Add(new DesignerActionTextItem("Hello world", "Category1"));
items.Add(new DesignerActionPropertyItem("Checked", "Sample checked item"));
return items;
}
public bool Checked {
get { return ((MyControl)base.Component).Prop; }
set { ((MyControl)base.Component).Prop = value; }
}
}
在GetSortedActionItems方法構建列表創建您自己的任務項目面板的關鍵。
這是快樂的版本。我應該注意到,在處理這個示例代碼時,我三次將Visual Studio崩潰到桌面。 VS2008是而不是對自定義設計器代碼中未處理的異常具有彈性。經常保存。調試設計時間代碼需要啓動VS的另一個實例,以停止調試器的設計時異常。
0
相關問題
- 1. 自定義Windows控件庫在C#
- 2. C#中的自定義控件事件#
- 3. Winforms中的自定義控件庫
- 4. 在c中的Windows Mobile自定義列表視圖控件#
- 5. ASP.NET C#中的自定義控件#
- 6. 用自定義的替換Windows控件
- 7. C#自定義控件的自定義事件WinForm
- 8. C#獲取自定義控件中的控件事件
- 9. Windows 8本地自定義控件
- 10. 造型自定義Windows Phone 7控件
- 11. Windows窗體 - 自定義用戶控件
- 12. 自定義Windows控制附件問題
- 13. 基於自定義控件庫中定義的樣式
- 14. ios SDK的自定義控件庫
- 15. StatusStip控件中的自定義控件
- 16. 自定義控件庫文件資源
- 17. 渲染ASP.NET中的自定義控件自定義控件派生自控制
- 18. 自定義控件(C#)中的雙緩衝區子控件
- 19. 用戶控件vs C#中的自定義控件#
- 20. aspnet自定義控件在自定義控件中丟失viewstate
- 21. C#+控件上的自定義圖形?
- 22. MVVM綁定到Windows Phone中的自定義控件
- 23. C#Designed不能識別自定義用戶控件中的自定義事件
- 24. C#窗體中的自定義控件Windows窗體鼠標事件問題
- 25. 處理在WPF自定義控件庫
- 26. 加載自定義樣式控件庫
- 27. 自定義控件自定義方法?
- 28. C#Winforms自定義WebBrowser控件需要
- 29. C#Winforms自定義控件幫助
- 30. C#自定義控件重繪慢