탭의 오른쪽 가장자리에 닫기 X가있는 탭을 정확하게 칠할 수 있도록 사용자 지정 TabControl 위젯을 만들려고했습니다. 모든 탭을 보유하는 사용자 지정 배열 클래스가 있습니다.Control.ControlCollection을 재정의하는 올바른 방법
그래서 Reflect Serialization 중에 숨길 수 있도록 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();
}
}
는 현재이 작동하지만 컨트롤 클래스는 여전히 기본 ArrayList에 있지만 tabPages 배열을 변경하는 등의 방법의되는 setChildIndex를 호출 할 수 있습니다.
xTabControl을 사용하여 새 xTabPage 객체를 등록 할 때 기본 클래스를 사용해야하는 새로운 ControlCollection 클래스가 필요 없게되고 싶습니다.
저는 이미 .Net Reflector를 사용하여 클래스 구조를 거쳤습니다. 나는 새로운 위젯의 등록을 얻으려면 Control 클래스의 절반을 복사 할 필요가 없기를 바란다.
나는 이것이 긴 발사임을 알고 있지만 누구든지이 일을 성공적으로 수행 했습니까?
필자는 여러 가지 이유로 탭 크기를 제어 할 수없는 등의 이유로 WinForms 표준 TabControl (현재 3rd party 컨트롤 사용)을 사용자 지정하지 않았습니다. 그러나 관련성이있는 일부 리소스는 다음과 같습니다. http : // dotnetrix. co.uk/tabcontrol.htm ... http://www.codeproject.com/KB/dotnet/CustomTabControl.aspx ... http://www.codeproject.com/KB/tabs/flattabcontrol.aspx ... 이 코드 프로젝트 기사에 대한 의견에는 다른 링크와 많은 문제점이 있습니다. 행운을 빕니다 ! – BillW