且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Dynemically在c#中添加和删除控件

更新时间:2023-12-06 08:08:28

的一步一步的过程创建一个新的Windows窗体项目。只在表单上放一个按钮。现在打开Form1.Designer.cs。在那里,您可以看到自动生成的表单代码。这就是Visual Studio Forms Designer在其中创建表单和控件的方式。



更改代码的价值有限,因为下次更改时会被覆盖设计师的努力和重建你的项目。



而是从代码中学习工作代码的样子。



按照您的意愿使示例复杂化并尝试在另一个项目中执行您想要执行的操作。您可以同时打开多个Visual Studio实例,因此在查看此处项目和尝试项目之间切换很容易。


Hii Experts

I am working on c# application now I want to add c# textbox and remove button dynamically when I press "add more" button.

now when I press remove button it will remove particular button and textbox.

Will any one help me to explain step by step process of this

Create a new Windows Forms project. Put only one button on the form. Now open Form1.Designer.cs. There you can see the automatically generated code for your form. This is how the Visual Studio Forms Designer creates forms and controls in them.

Changing code in there has limited value because it will get overwritten the next time you change the slightest nouance in the designer and rebuild your project.

Instead learn from the code there what working code can look like.

Complicate the example at your will and try to do what you want to do in another project. You can have several instances of Visual Studio open at the same time, so switching between the "look here" project and the "trying that" is easy.