cuốn sách gpt4 ai đã làm

C# Sử dụng TabPage tùy chỉnh để thay đổi TabPage mặc định trong TabControl

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-03 20:53:39 29 4
mua khóa gpt4 Nike

我创建了一个自定义 TabControl 和一个自定义 Trang tab,如下所示:

Tùy chỉnh TabControl Mã số:

public class MyCustomTabControl : TabControl
{
//Some Custom Properties

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

}
}

Tùy chỉnhTrang tab:

public class MyCustomTabPage : TabPage
{
//Some Custom Properties

public MyCustomTabPage() : base()
{
this.BackColor = System.Drawing.Color.Transparent;
}
}

我该怎么做才能在表单中添加自定义控件 MyCustomTabControl 时,它会添加名为 MyCustomTabPage Tùy chỉnh Trang tab。目前它从 Windows 添加 Trang tab.

câu trả lời hay nhất

您需要执行一些步骤,首先定义一个类,例如 MyCustomTabCollection 并为您的 MyCustomTabCollection 类实现所有三个接口(interface)方法,然后声明一个 MyCustomTabCollection 实例 trong của bạn MyCustomTabControl 上作为 công cộng tài sản.

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
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress