C# WIN程序的问题,本人新手请大家多多指教
C# WIN程序。我点击textBox把隐藏的panel容器(容器里有复选框)显示出来,现在我要做点击panel容器以外的地方,都要隐藏panel容器。我该怎么做。
------解决方案--------------------panel1的LostFocus事件里面写
panel1.Hide();
------解决方案--------------------private void textBox1_Enter(object sender, EventArgs e)
{
panel1.Visible = true;
}
private void textBox1_Leave(object sender, EventArgs e)
{
panel1.Visible = false;
}
------解决方案--------------------确实考虑不周
public Form1()
{
InitializeComponent();
foreach (Control control in this.Controls)
{
if (control != textBox1 && control != panel1)
{
control.Enter += GroupInvisible;
}
}
}
private void GroupVisible(object sender, EventArgs e)
{
panel1.Visible = true;
}
private void GroupInvisible(object sender, EventArgs e)
{
panel1.Visible = false;
}
------解决方案--------------------楼上正解!·