C#如何动态构建按钮并将其保留在应用程序上

编程入门 行业动态 更新时间:2024-10-27 19:26:23
本文介绍了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 sampleDynamically 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#如何动态构建按钮并将其保留在应用程序上

本文发布于:2023-11-13 14:08:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   按钮   动态   并将其

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!