C#使用自定义TabPage更改TabControl中的默认TabPage
我创建了一个自定义C#使用自定义TabPage更改TabControl中的默认TabPage,c#,winforms,tabcontrol,tabpage,C#,Winforms,Tabcontrol,Tabpage,我创建了一个自定义TabControl和一个自定义TabPage,如下所示: 自定义TabControlcode: public class MyCustomTabControl : TabControl { //Some Custom Properties public MyCustomTabControl () : base() { base.Width = 200; base.Height = 100; } } 自定义选项卡
TabControl
和一个自定义TabPage
,如下所示:
自定义TabControl
code:
public class MyCustomTabControl : TabControl
{
//Some Custom Properties
public MyCustomTabControl () : base()
{
base.Width = 200;
base.Height = 100;
}
}
自定义选项卡页面
:
public class MyCustomTabPage : TabPage
{
//Some Custom Properties
public MyCustomTabPage() : base()
{
this.BackColor = System.Drawing.Color.Transparent;
}
}
如何才能在表单中添加自定义控件
MyCustomTabControl
时,添加名为MyCustomTabPage
的自定义TabPage
。目前,它正在从windows添加选项卡页面。您需要执行一些步骤,首先定义一个类,例如MyCustomTabCollection
,并为您的MyCustomTabCollection
类实现所有三种接口方法,然后将MyCustomTabControl
上的MyCustomTabCollection
实例声明为public
属性
实现接口
实施所有方法
声明您的CustomTabPageCollection
如果还有问题,请告诉我。您需要执行一些步骤,首先定义一个类,例如MyCustomTabCollection
,并为您的MyCustomTabCollection
类实现所有三种接口方法,然后将MyCustomTabControl
上的MyCustomTabCollection
实例声明为public
属性
实现接口
实施所有方法
声明您的CustomTabPageCollection
如果还有问题,请告诉我。您不能使用设计器,必须使用代码。在InitializeComponent()调用之后,在表单的构造函数中编写它。当心TabControl。你不能用设计器,你必须用代码。在InitializeComponent()调用之后,在表单的构造函数中编写它。当心那个TabControl。
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();
}
public class MyCustomTab : TabControl
{
public MyCustomTabPageCollection TabPages { get; set; }
public MyCustomTab() : base()
{
base.Width = 200;
base.Height = 100;
}
}