如何在运行时设计控件 [英] How to design controls at runtime

查看:74
本文介绍了如何在运行时设计控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我可以在运行时设计控件,在运行时调整控件大小并删除它们吗?我有餐厅应用程序,有一种表格必须设计表格(按钮).

最好的问候,
Bujar Akiki

Hello,

Can I design controls at runtime, resizing and dropping controls at runtime. I have restaurant application, there is a form where I have to design tables (buttons).

Best regards,
Bujar Akiki

推荐答案

Bujar,

是的,您可以动态创建控件,并利用PropertyGrid更改该控件的外观.

希望对您有所帮助.

已修改:

这是我发现的:
我创建了一个包含PropertyGrid,面板和按钮的表单. button事件处理程序创建一个新按钮 button = new Button()并将其添加到面板Panel1.Controls.Add(button)中.
属性网格通过PropertyGrid1.ObjectSelected = button挂接到按钮上,并预先存储:动态创建了一个按钮,可以通过属性网格对其进行操作.

.NET框架不是整洁的;)

最终修改:

干杯


Manfred
Hi Bujar,

yes, you can create your controls dynamically and make use of the PropertyGrid to make changes to the appearance of that control.

Hope this is some help.

Modified:

This is what I found out:
I created a form that contained a PropertyGrid a Panel and a Button. The buttons event handler creates a new button button = new Button() and adds that to the panel Panel1.Controls.Add(button).
The property grid is hooked to the button via PropertyGrid1.ObjectSelected = button and presto: A button was dynamically created and can be manipulated via the property grid.

Ain''t that .NET framework neat ;)

End Modification:

Cheers


Manfred


private void AddControls_Click(object sender, EventArgs e)
       {
           Button newButton = new Button { Text = "New Button" };
           CheckBox newCheckBox = new CheckBox { Text = "New CheckBox", ThreeState = true };
           List<Control> lst = new List<Control>();
           lst.Add(newButton);
           lst.Add(newCheckBox);
           this.Controls.AddRange(lst.ToArray());
       }


这篇关于如何在运行时设计控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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