本文介绍了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#在运行时添加具有值的按钮
发布评论