[英]C# Change the Default TabPage in TabControl using Custom TabPage
我创建了一个自定义TabControl
和一个自定义TabPage
如下所示:
自定义TabControl
代码:
public class MyCustomTabControl : TabControl
{
//Some Custom Properties
public MyCustomTabControl () : base()
{
base.Width = 200;
base.Height = 100;
}
}
自定义TabPage
:
public class MyCustomTabPage : TabPage
{
//Some Custom Properties
public MyCustomTabPage() : base()
{
this.BackColor = System.Drawing.Color.Transparent;
}
}
我该怎么做,以便当我在表单中添加自定义控件MyCustomTabControl
时,它将添加名为MyCustomTabPage
的自定义TabPage
。 当前它从Windows添加TabPage
。
你需要做一些步骤,首先定义一个类如MyCustomTabCollection
和实施所有三个接口方法MyCustomTabCollection
类,则声明的实例MyCustomTabCollection
您MyCustomTabControl
作为public
财产。
实施接口
public class MyCustomTabPageCollection : IList, ICollection, IEnumerable
{
// implement all three interfaces
}
实施所有方法
public object this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool IsReadOnly => throw new NotImplementedException();
public bool IsFixedSize => throw new NotImplementedException();
public int Count => throw new NotImplementedException();
public object SyncRoot => throw new NotImplementedException();
public bool IsSynchronized => throw new NotImplementedException();
public int Add(object value)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(object value)
{
throw new NotImplementedException();
}
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
public int IndexOf(object value)
{
throw new NotImplementedException();
}
public void Insert(int index, object value)
{
throw new NotImplementedException();
}
public void Remove(object value)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
声明您的CustomTabPageCollection
public class MyCustomTab : TabControl
{
public MyCustomTabPageCollection TabPages { get; set; }
public MyCustomTab() : base()
{
base.Width = 200;
base.Height = 100;
}
}
如果有问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.