【问题标题】:Bring window to the front [duplicate]将窗口放在前面[重复]
【发布时间】:2012-10-05 21:40:37
【问题描述】:

可能重复:
Restore WindowState from Minimized

我有一个通常隐藏在托盘栏中的窗口。

如果它被隐藏了,我想显示它,并带到前面。

如果它已经打开了,我只想把它放在前面。

如果它被最小化到任务栏,那么我想将它展开并放在前面。

现在我的 show 方法中有这个:

this.Show();
this.Activate();
this.ShowInTaskbar = true;
this.TopMost = true;
this.Focus();

但如果它被最小化,它就不会扩展。

如何解决这个问题?

【问题讨论】:

标签: c# .net winforms


【解决方案1】:

尝试添加this.WindowState = FormWindowState.Maximized

有关 FormWindowState 枚举的完整详细信息,请参阅here

【讨论】:

  • 我可能会选择FormWindowState.Normal 而不是Maximized
【解决方案2】:

如果它被最小化,您将不得不使用WindowState 属性来恢复窗口。

 this.WindowState = FormWindowState.Maximized; // To maximize
 this.WindowState = FormWindowState.Normal; // To restore

【讨论】:

    【解决方案3】:
    if (this.WindowState == FormWindowState.Minimized)
        this.WindowState = FormWindowState.Normal;    
    
    this.Show();
    this.Activate();
    this.ShowInTaskbar = true;
    this.TopMost = true;
    this.Focus();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 2015-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多