将控制从其他形式的可见 [英] Set control visible from other form
本文介绍了将控制从其他形式的可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设置按钮的可见属性设置为false 窗体2
的。我将如何使按钮(窗体2
)可见,当我点击一个按钮(一个按钮,也可以打开窗体2
)的 Form1中
。
我试过这样:
私人无效的button1_Click(对象发件人, EventArgs五)
{
窗体2 F2 =新Form2的();
f2.Show();
f2.button1.Visible = TRUE;
f2.button1.Location =新的点(200,200);
}
解决方案
在Form2的创建方法
公共无效setButton1Visible(布尔标志){
this.button1.Visible =标志;
}
您不能直接从Form1中访问按钮。 (其实你可以,但它不是解决它正确的方式。
私人无效的button1_Click(对象发件人,EventArgs五)
{
窗体2 F2 =新Form2的();
f2.Show();
f2.setButton1Visible(真);
}
I set the button visible property to false of Form2
. How I will make the button(Form2
) visible when I click a button(a button that also opens Form2
) from Form1
.
I tried this :
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
f2.button1.Visible = true;
f2.button1.Location = new Point(200, 200);
}
解决方案
Create a method in Form2
public void setButton1Visible(boolean flag){
this.button1.Visible = flag;
}
You cannot access the button directly from Form1. (Actually you can,but it is not right way to solve it.
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
f2.setButton1Visible(true);
}
这篇关于将控制从其他形式的可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文