c# winform 如何在一个button按钮的click事件中 修改当前窗体的size
2个回答
展开全部
因为不在同一个实例中.也没关联起来.
最简单的解决方案就是定义为全局.
例如:
private Form fm1;
private Button button;
private TextBox tbd;
private void button1_Click(object sender, EventArgs e)
{
fm1 = new Form();
fm1.StartPosition = FormStartPosition.CenterScreen;
fm1.Size = new System.Drawing.Size(400, 160);
fm1.Text = "测试";
button = new Button();
button.Name = "button";
button.Text = "登陆";
button.Location = new Point(10, 10);
button.Size = new Size(24, 57);
button.Click += button_Click;
tbd = new TextBox();
tbd.Name = "TextBox";
tbd.Text = "测试文本";
tbd.Location = new Point(50, 10);
tbd.Size = new Size(24, 57);
fm1.Controls.Add(tbd);
fm1.Controls.Add(button);
fm1.Show();
}
void button_Click(object sender, EventArgs e)
{
string AA = tbd.Text;
}
最简单的解决方案就是定义为全局.
例如:
private Form fm1;
private Button button;
private TextBox tbd;
private void button1_Click(object sender, EventArgs e)
{
fm1 = new Form();
fm1.StartPosition = FormStartPosition.CenterScreen;
fm1.Size = new System.Drawing.Size(400, 160);
fm1.Text = "测试";
button = new Button();
button.Name = "button";
button.Text = "登陆";
button.Location = new Point(10, 10);
button.Size = new Size(24, 57);
button.Click += button_Click;
tbd = new TextBox();
tbd.Name = "TextBox";
tbd.Text = "测试文本";
tbd.Location = new Point(50, 10);
tbd.Size = new Size(24, 57);
fm1.Controls.Add(tbd);
fm1.Controls.Add(button);
fm1.Show();
}
void button_Click(object sender, EventArgs e)
{
string AA = tbd.Text;
}
追问
这样是新打开了一个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询