我开始创建一个自定义的TabControl小部件,这样我就可以在选项卡的右边缘使用关闭X精确地绘制选项卡。我有一个自定义数组类,它包含所有的选项卡。正确的方法来覆盖Control.ControlCollection
所以我重写CreateControlsInstance实例类并重新定义Controls类,以便在反射序列化过程中隐藏它。
protected override Control.ControlCollection CreateControlsInstance() {
return new ControlCollection(this);
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
private new Control.ControlCollection Controls {
get { return base.Controls; }
}
然后我创建覆盖类。
public new class ControlCollection: Control.ControlCollection {
private xTabControl owner;
public ControlCollection(xTabControl owner): base(owner) {
this.owner = owner;
}
public override void Add(Control value) {
if (!(value is xTabPage))
throw new Exception("The control must be of type xTabPage");
xTabPage tabPage = (xTabPage)value;
if (!owner.inTabEvent)
owner._tabPages.Add(tabPage);
base.Add(value);
}
public override void Remove(Control value) {
if (!(value is xTabPage))
throw new Exception("The control must be of type JDMX.Widget.xTabPage");
if (!owner.inTabEvent) {
xTabPage tabPage = (xTabPage)value;
owner._tabPages.Remove(tabPage);
}
base.Remove(value);
}
public override void Clear() {
owner._tabPages.Clear();
}
}
目前这个工作,但如果控件类仍然可以调用方法SetChildIndex,等这改变了底层数组列表,但不是的TabPages阵列。
我希望能够消除新的ControlCollection类必须使用基类来注册xTabControl对象的新xTabPage对象。
我已经通过.Net反射器的类结构。我希望不必复制Control类的一半,以便让新小部件的注册工作。
我知道这是一个远投,但有没有人有这样做的成功?
我放弃了自定义WinForms标准TabControl(现在使用第三方控件),原因很多:无法控制标签大小等。但是这里有一些可能相关的资源:http:// dotnetrix。 co.uk/tabcontrol.htm ... http://www.codeproject.com/KB/dotnet/CustomTabControl.aspx ... http://www.codeproject.com/KB/tabs/flattabcontrol.aspx ...在对这些代码项目文章的评论中,您会发现其他链接和许多问题。祝你好运 ! – BillW 2010-02-23 03:30:21