繁体   English   中英

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

[英]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类,则声明的实例MyCustomTabCollectionMyCustomTabControl作为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM