C#表格生成 [英] C# Form Generation

查看:238
本文介绍了C#表格生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以基于列表/数据库在表单上自动生成项目?
因此,例如,一个文本框和一个用于库存清单上每个项目的两个按钮,一旦创建了库存清单,就可以单击一个按钮,这将生成一个新表格.

Is it possable to auto generate items on a form based on a list/database?
So for example a text box and two buttons for each item on a stock list, once the stock list has been created a button can be clicked which would generate a new form.

推荐答案

是的,为什么不呢.只需在运行时将这些控件添加到Controls集合中,如下所示:

Yes, why not. Just in runtime add those controls in Controls collection like this :

Form f = new Form();
TextBox tb = new TextBox();
tb.Losition = new Point(...);
// define properties here
f.Controls.Add(tb);



只需对所有控件执行此操作,我认为您的表单将起作用.

干杯.
:rose:



Just do this for all controls and I think your form will work.

Cheers.
:rose:


我想您正在使用Windows窗体?

确实有可能.控件只是特定类的对象.查看您的Form1.Designer.cs文件.这就是设计者如何在表单上保留控件.这只是普通的C#.

但是要警惕在一种表单上创建太多控件.并且,创建新控件后,别忘了调用myForm.Controls.Add( myNewControl ).

尼克
I presume you are using Windows Forms?

It is indeed possible. Controls are just objects of a particular class. Look at your Form1.Designer.cs file. This is how the designer persists the controls on your form. It''s just normal C#.

Be wary about creating too many controls on one form, though. And don''t forget to call myForm.Controls.Add( myNewControl ) when you have created the new controls.

Nick


这篇关于C#表格生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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