[英]TabControl - Loading Default UI Elements in New Tab
I have a TabControl in my application but I want to allow the user to create a new tab, but when the new tab is created it contains some default form controls. 我的应用程序中有一个TabControl,但是我想允许用户创建一个新的选项卡,但是当创建新的选项卡时,它包含一些默认的表单控件。 All new tabs created will contain the same basic form controls per tab (think NotePad++ where each new tab has a text editor within it).
创建的所有新选项卡每个选项卡都将包含相同的基本表单控件(请注意NotePad ++,其中每个新选项卡中都有一个文本编辑器)。
Is there some sort of design pattern or template I can use so that when a new tab is created it will contain the necessary form controls required by my application? 我是否可以使用某种设计模式或模板,以便在创建新选项卡时将包含应用程序所需的必要表单控件?
Just to convey some meaning a little more: 只是为了传达一些含义:
... and the processes repeats for any number of tabs that the user requires. ...,然后针对用户需要的任意数量的选项卡重复该过程。
Like the comments suggest you should create a UserControl
, lets say you call it TextEditorControl
. 就像评论建议您应该创建一个
UserControl
,假设您将其称为TextEditorControl
。 Then you can add tab pages on a button click using the following method 然后,您可以使用以下方法在单击按钮时添加标签页
private void AddTabPage()
{
// Add new tab page and dock fill.
TabPage tab = new TabPage(Path.GetFileName(fullPath));
TextEditorControl editor = new TextEditorControl();
editor.Dock = System.Windows.Forms.DockStyle.Fill;
// Add the new tab to the tab control.
tab.Controls.Add(editor);
fileTabs.Controls.Add(tab);
fileTabs.SelectedTab = tab;
}
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.