C#如何动态构建按钮并将其保留在应用程序上 [英] C# How to build buttons dynamically and keep it on the application

查看:100
本文介绍了C#如何动态构建按钮并将其保留在应用程序上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式在tabpage上构建按钮,并且我希望保留应用程序上的所有按钮以在每次登录时使用它。

此按钮名称应来自数据库项目表。

I want to build buttons on tabpage programmatically, and I want to keep all buttons on application to use it in each login.
this buttons name should be from database item table.

推荐答案

您好,

以下从SQL-Server数据库表中读取的信息创建按钮,并显示如何使用click按钮的事件。

The following creates button from information read from a SQL-Server database table and shows how to work with click events for the buttons.

警告,我没有使用TabControl但你应该能够使用所呈现的内容来实现这一点。例如,如果按钮需要位于特定选项卡上,则需要在表中添加一个字段,该字段按名称或索引指定选项卡。 如果
这是一个不同的数据库,例如Oracle或MS-Access当然需要更改基础SQL和数据提供程序,例如从SqlClient说OleDb等。如果你已经指出数据库,我仍然会把它作为工作的蓝图。

Caveat, I'm not using a TabControl yet you should be able to work with what is presented to achieve this. For example, if buttons need to be on specific tabs you would need to add a field in the table that specifies the tab by name or by index.  If this is a different database e.g. Oracle or MS-Access you would of course need to change the underlying SQL and data provider e.g. from SqlClient to say OleDb etc. If you had indicated the database I still would had presented this as a blueprint to work from.

我的MSDN代码示例  从SQL-Server数据库动态创建窗体表单按钮。在这种情况下,该表来自Microsoft NorthWind。

My MSDN code sample Dynamically create window form buttons from a SQL-Server database. In this case the table is from Microsoft NorthWind.

响应点击事件(我显示一个新窗口,但你可以做任何你想做的事)

Responding to a click event (I show a new window but you can do whatever you want)


这篇关于C#如何动态构建按钮并将其保留在应用程序上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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