我创建了一个自定义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。目前,它从窗口添加TabPage。
发布于 2018-10-10 05:15:08
您需要执行一些步骤,首先定义类MyCustomTabCollection并为MyCustomTabCollection类实现所有三个接口方法,然后将MyCustomTabControl上的MyCustomTabCollection实例声明为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;
}
}如果有什么问题,请告诉我。
https://stackoverflow.com/questions/52732514
复制相似问题