在 C# 中打开表单 [英] opening forms in c#

查看:28
本文介绍了在 C# 中打开表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第一个表单中有一个按钮.如果我单击该按钮,第二个表单正在打开,如果我再次单击第一个表单中的同一个按钮,另一个第二个表单正在打开.我只需要在 c# 中打开一个第二个表单.

I had a button in first form .if i click the button the second form is opening ,if i click again same button in first form another second form is opening.i need to open only one second form only in c# .

推荐答案

好吧,你可以这样做:

Form.ShowDialog()

这将阻止用户点击第一个表单上的按钮,因为第二个表单将保持焦点直到它关闭.

This will prevent the user clicking the button on the first form, as the second form will keep focus until it is closed.

或者你可以这样做

Form2 form2 = null;

void button_click(object sender, EventArgs e)
{ 
   if(form2 == null)
   {
      form2 = new Form2();
      form2.Disposed += new EventHandler(f_Disposed);
      form2.Show();
   }
}

void f_Disposed(object sender, EventArgs e)
{
   form2 = null;
}

这篇关于在 C# 中打开表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆