打开现有表格

时间:2014-08-13 19:56:40

标签: c# winforms openform newforms

我有这段代码:

  private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
  {
      Form8 of = new Form8();
      of.ShowDialog();
  }

该按钮打开我的form8(好)。 但如果我点击两次,表格会重复,所以我得到了2张相同的表格。

当我第二次点击链接标签时,是否有人知道如何选择(带到前面)form8(如果它已经打开)。 谢谢!

1 个答案:

答案 0 :(得分:0)

public class MainForm
{
    // Keep a reference to your popup form here, so you never create more than one instance
    private Form8 of = new Form8();

    private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
    {
        if (of != null && of.IsDisposed)
            of = new Form8();

        // Call Show(), not ShowDialog() because ShowDialog will block the UI thread
        // until you close the dialog.
        of.Show();
        of.BringToFront();
    }
}