C#在运行时添加具有值的按钮

编程入门 行业动态 更新时间:2024-10-11 09:27:28
本文介绍了C#在运行时添加具有值的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在运行时将带有值的按钮添加到我的选项卡控件中。许多教程都展示了创建数据库连接时如何完成的。

I would like to add a button with value to my tab control during runtime. A lot of tutorial show how it's done while creating connecting with database. Is there any way that it can be done without connecting to database?

将数据输入到文本框中并单击保存后,新按钮应出现在另一窗体的选项卡控件上。

After I input data into both textbox and clicked save, new button should appear on tab control on another form.

推荐答案

在保存按钮中放置:

private void btnSave_Click(object sender, EventArgs e) { x = 4; y = panel1 .Controls.Count * 70; Button newButton = new Button (); newButton.Height = 150; newButton.Width = 60; newButton.Location = new Point(x, y); newButton.Text= "your text"; newButton.Click += new System.EventHandler(Button_Click); tabControl1.TabPages [0].Controls.Add(newButton); }

也可以单击创建的新按钮:

And also you can handel the click of new button created :

public void Button_Click(object sender, EventArgs e) { Button button = (Button)sender ; MessageBox.Show("Button is pressed "+button .Text ); }

更多推荐

C#在运行时添加具有值的按钮

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

发布评论

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

>www.elefans.com

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