如何创建类似于“创建新标签”的浏览器并在C#中的Windows窗体应用程序中运行时添加控件 [英] How Can I Create Browser Like "Create New Tab" And Add Controls To It At Runtime In Windows Forms Application In C#

查看:234
本文介绍了如何创建类似于“创建新标签”的浏览器并在C#中的Windows窗体应用程序中运行时添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#中的Windows窗体应用程序中的项目,其中点击 LOAD 按钮 a NEW TABPAGE 创建文本框,标签,treeView加载数据。这个新的TabPage将在一个单独的TabPage 中打开,而不是在当前窗口中打开。

重点是我对Windows表单开发全新,我不知道如何完成上述任务。

如果您可以将我重定向到一些精细教程或某些代码片段,那么它将会有很大的帮助。

提前感谢!!!

I am working on a project in Windows Forms Application in C# wherein on clicking LOAD button a NEW TABPAGE is created with textboxes,labels,treeView loaded with data. This new TabPage is to be opened in a separate TabPage and not on the current window.
The point is i am totally new to Windows forms development and i don't know how to accomplish the above task.
If you can either redirect me to some fine tutorials or to some code snippets ,then it will be of great help.
thanks in advance!!!

推荐答案

在TabControl中动态创建新标签非常简单。



这里有一些代码放在你的button_Click()中:

Dynamically creating a new tab in a TabControl is pretty simple.

Here is some code to put in your button_Click() :
// Instanciate a TabPage
TabPage myTab = new TabPage("My TabPage");
            
// If you want to create your controls manually, then here we go...
Label myLabel = new Label();
myLabel.Text = "This is a label";

// Add your controls in it
myTab.Controls.Add(myLabel);

// Don't forget to add your TabPage in the TabPageCollection
tabControl1.TabPages.Add(myTab);



手动实例化控件有点奇怪,你可能想要创建一个UserControl。

创建UserControl后,您可以轻松地以相同的方式将其添加到TabPage:


This is kinda weird to instantiate your controls manually though, you may want to create a UserControl instead.
After created your UserControl, you can easily add it to your TabPage the same way :

myTab.Controls.Add(new MyUserControl());



如果您手动创建控件,您应该知道如何填充它们,但是,如果您决定使用UserControl,将ID或实体作为参数传递给UserControl构造函数并填充它。


If you create your controls manually, you should know how to populate them, however, if you decide to use a UserControl, pass an ID or an entity as a parameter to your UserControl constructor and populate it.


这篇关于如何创建类似于“创建新标签”的浏览器并在C#中的Windows窗体应用程序中运行时添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆