最大化的表格应该涵盖任务栏,即使在切换正常最大化后

时间:2018-04-17 01:57:17

标签: c# winforms

我正在用C#编写一个Windows窗体应用程序,它包含一个没有标题的最大化窗口,它应该最大化并覆盖任务栏(即通过任务栏)。这很简单,只需执行以下操作即可实现:

Text = "";
ControlBox = false;
FormBorderStyle = FormBorderStyle.None;

..在我打开表单之前。问题是,我也希望能够通过击键来切换这种行为,这样我就可以显示它的标准化(带标题)然后能够回到最大化(没有标题)。问题是,当我回到最大化时,窗口不再覆盖任务栏,它是可见的,它不应该是。

是否有人知道这是否可以显示,即没有标题栏覆盖任务栏的最大化窗口,或者只有在第一次打开窗口时才可能?也可以来回切换?

1 个答案:

答案 0 :(得分:0)

这应该有效:

bool IsFullScreen = false;      // Set this to true if you initially open 
                                // your form in full screen.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.F)
    {
        if (!IsFullScreen)
        {
            // Changing the WindowState helps keeping the form over the taskbar.
            WindowState = FormWindowState.Normal;       
            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            IsFullScreen = true;
        }
        else
        {
            FormBorderStyle = FormBorderStyle.Sizable;
            // WindowState = FormWindowState.Normal;   // uncomment this if you also don't 
                                                       // want the form to be maximized.
            IsFullScreen = false;
        }
    }
}

它允许您通过按 F 键在正常最大化(或恢复)和全屏之间切换表单。如果您希望从表单上的任何控件中捕获击键,则可能需要将表单的KeyPreview属性设置为true

希望有所帮助。

相关问题