gpt4 book ai didi

C# 使用自定义 TabPage 更改 TabControl 中的默认 TabPage

转载 作者:太空宇宙 更新时间:2023-11-03 20:53:39 29 4
gpt4 key购买 nike

我创建了一个自定义 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 类实现所有三个接口(interface)方法,然后声明一个 MyCustomTabCollection 实例 在您的 MyCustomTabControl 上作为 public 属性。

Implement interfaces

public class MyCustomTabPageCollection : IList, ICollection, IEnumerable
{
// implement all three interfaces
}

Implement all methods

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();
}

Declare your CustomTabPageCollection

public class MyCustomTab : TabControl
{
public MyCustomTabPageCollection TabPages { get; set; }

public MyCustomTab() : base()
{
base.Width = 200;
base.Height = 100;

}
}

如果还有问题,请告诉我。

关于C# 使用自定义 TabPage 更改 TabControl 中的默认 TabPage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52732514/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com