我想在运行时向我的选项卡控件添加一个具有值的按钮。许多教程展示了创建与数据库的连接时是如何完成的。有没有什么方法可以在不连接数据库的情况下完成?
在我将数据输入到两个文本框中并单击“保存”后,新按钮应该出现在另一个窗体上的选项卡控件上。
在保存按钮中放置:
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);
}
您还可以处理创建的新按钮的单击:
public void Button_Click(object sender, EventArgs e)
{
Button button = (Button)sender ;
MessageBox.Show("Button is pressed "+button .Text );
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)