我开始创建一个自定义的TabControl小部件,这样我就可以在选项卡的右边缘精确地绘制一个接近X的选项卡。我有一个包含所有选项卡的自定义数组类。
因此,我重写createControlsInstance实例类并重新定义控件类,以便在反射序列化期间隐藏它。
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等,这将更改基础的ArrayList,但不会更改TabPages数组。
我希望能够消除新的ControlCollection类必须使用基类向XtabControl注册新的XtabPage对象的需要。
我已经通过了.NET Reflector的类结构。我希望不必复制控制类的一半,这样就可以注册新的小部件。
我知道这是一个长期的尝试,但有没有人成功做到这一点?