如何在我自己的自定义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. 定义一个Windows窗体自定义控件的事件
- 9. 如何在C#中自定义控件?
- 10. C#获取自定义控件中的控件事件
- 11. 自定义Windows控制附件问题
- 12. Windows 8本地自定义控件
- 13. Windows窗体 - 自定义用户控件
- 14. 造型自定义Windows Phone 7控件
- 15. 基于自定义控件库中定义的样式
- 16. ios SDK的自定义控件库
- 17. StatusStip控件中的自定义控件
- 18. 自定义控件库文件资源
- 19. 渲染ASP.NET中的自定义控件自定义控件派生自控制
- 20. 自定义控件(C#)中的双缓冲区子控件
- 21. 用户控件vs C#中的自定义控件#
- 22. C#+控件上的自定义图形?
- 23. aspnet自定义控件在自定义控件中丢失viewstate
- 24. C#,自定义文件上传控件
- 25. MVVM绑定到Windows Phone中的自定义控件
- 26. C#Designed不能识别自定义用户控件中的自定义事件
- 27. C#窗体中的自定义控件Windows窗体鼠标事件问题
- 28. 如何将Windows窗体控件应用于WPF自定义控件库?
- 29. 公开在另一个自定义控件的控件模板中定义的自定义控件事件
- 30. 加载自定义样式控件库