按钮创建一个按钮然后那个按钮 show/hide 形式
Button creates a button then that button show/hide form
我已经知道如何在单击按钮时创建按钮。为了能够 show/hide 表格,我应该在这几行旁边写什么代码?
Button b1 = new Button();
b1.Location = new Point (21, 0);
b1.Name = "";
b1.Size = new Size(120, 100);
b1.FlatStyle = FlatStyle.Flat;
b1.Image = TITOMS_LOGIN.Properties.Resources.icon1_1_;
b1.BackColor = Color.Transparent;
Button b2 = new Button();
b2.Location = new Point(21, 99);
b2.Name = "";
b2.Size = new Size(120, 100);
b2.FlatStyle = FlatStyle.Flat;
b2.Image = TITOMS_LOGIN.Properties.Resources.icon2_1_;
b2.BackColor = Color.Transparent;
Button b3 = new Button();
b3.Location = new Point(21, 198);
b3.Name = "";
b3.Size = new Size(120, 100);
b3.FlatStyle = FlatStyle.Flat;
b3.Image = TITOMS_LOGIN.Properties.Resources.icon3_1_;
b3.BackColor = Color.Transparent;
Button b4 = new Button();
b4.Location = new Point(21, 297);
b4.Name = "";
b4.Size = new Size(120, 100);
b4.FlatStyle = FlatStyle.Flat;
b4.Image = TITOMS_LOGIN.Properties.Resources.icon2_1_;
b4.BackColor = Color.Transparent;
for each button they show different form
For example: Button 1 shows Form 1 and Hide others
Button 2 shows Form 2 and hide others
您应该处理按钮单击事件,并且在每个事件中您必须实例化所需的表单并使用 Show() 方法显示它。
你有按钮。
您需要按钮的事件来执行操作。
b1.Click += new System.EventHandler(button1_Click);
b2.Click += new System.EventHandler(button2_Click);
b3.Click += new System.EventHandler(button3_Click);
b4.Click += new System.EventHandler(button4_Click);
button1_Click 是一种方法,每当单击按钮时都会调用它。
如果你想显示一个新表格:
private void button1_Click(object sender, EventArgs e)
{
Form form = new Form();
form.Show();
}
如果要关闭其他窗体,窗体必须是全局的。
Form2 form1;
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
//Create new Form
form2 = new Form2();
form2.Show();
//Check if other Form1 is not null -> it was initialized
if (form1 != null )
{
form1.Close();
form1.Dispose();
form1 = null;
}
}
我已经知道如何在单击按钮时创建按钮。为了能够 show/hide 表格,我应该在这几行旁边写什么代码?
Button b1 = new Button();
b1.Location = new Point (21, 0);
b1.Name = "";
b1.Size = new Size(120, 100);
b1.FlatStyle = FlatStyle.Flat;
b1.Image = TITOMS_LOGIN.Properties.Resources.icon1_1_;
b1.BackColor = Color.Transparent;
Button b2 = new Button();
b2.Location = new Point(21, 99);
b2.Name = "";
b2.Size = new Size(120, 100);
b2.FlatStyle = FlatStyle.Flat;
b2.Image = TITOMS_LOGIN.Properties.Resources.icon2_1_;
b2.BackColor = Color.Transparent;
Button b3 = new Button();
b3.Location = new Point(21, 198);
b3.Name = "";
b3.Size = new Size(120, 100);
b3.FlatStyle = FlatStyle.Flat;
b3.Image = TITOMS_LOGIN.Properties.Resources.icon3_1_;
b3.BackColor = Color.Transparent;
Button b4 = new Button();
b4.Location = new Point(21, 297);
b4.Name = "";
b4.Size = new Size(120, 100);
b4.FlatStyle = FlatStyle.Flat;
b4.Image = TITOMS_LOGIN.Properties.Resources.icon2_1_;
b4.BackColor = Color.Transparent;
for each button they show different form
For example: Button 1 shows Form 1 and Hide others
Button 2 shows Form 2 and hide others
您应该处理按钮单击事件,并且在每个事件中您必须实例化所需的表单并使用 Show() 方法显示它。
你有按钮。
您需要按钮的事件来执行操作。
b1.Click += new System.EventHandler(button1_Click);
b2.Click += new System.EventHandler(button2_Click);
b3.Click += new System.EventHandler(button3_Click);
b4.Click += new System.EventHandler(button4_Click);
button1_Click 是一种方法,每当单击按钮时都会调用它。
如果你想显示一个新表格:
private void button1_Click(object sender, EventArgs e)
{
Form form = new Form();
form.Show();
}
如果要关闭其他窗体,窗体必须是全局的。
Form2 form1;
Form2 form2;
private void button1_Click(object sender, EventArgs e)
{
//Create new Form
form2 = new Form2();
form2.Show();
//Check if other Form1 is not null -> it was initialized
if (form1 != null )
{
form1.Close();
form1.Dispose();
form1 = null;
}
}