我有一个WinForms应用程序,我试图全屏(有点像VS在全屏模式下).
目前,我设置FormBorderStyle到None和WindowState到Maximized这给我多一点空间,但它并没有在任务栏覆盖,如果它是可见的.
我还需要做些什么才能使用这个空间?
对于奖励积分,我可以采取MenuStrip哪些措施让我的自动隐身也放弃这个空间吗?
Hen*_*man 142
对于基本问题,以下将做到这一点(隐藏任务栏)
private void Form1_Load(object sender, EventArgs e)
{
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}
但是,有趣的是,如果你交换最后两行,任务栏仍然可见.我认为使用属性窗口很难控制这些操作的顺序.
Zig*_*gnd 20
我一直在SO和其他一些网站寻找这个问题的答案,但是我给出的答案非常复杂,而其他一些答案根本无法正常工作,所以在经过大量的代码测试后我解决了这个难题.
注意:我使用的是Windows 8,而我的任务栏未处于自动隐藏模式.
我发现在执行任何修改之前将WindowState设置为Normal将使用未覆盖的任务栏停止错误.
我创建了这个有两种方法的类,第一种进入"全屏模式",第二种进入"全屏模式".因此,您只需要创建此类的对象,并将要设置为全屏的Form作为参数传递给EnterFullScreenMode方法或LeaveFullScreenMode方法:
class FullScreen
{
    public void EnterFullScreenMode(Form targetForm)
    {
        targetForm.WindowState = FormWindowState.Normal;
        targetForm.FormBorderStyle = FormBorderStyle.None;
        targetForm.WindowState = FormWindowState.Maximized;
    }
    public void LeaveFullScreenMode(Form targetForm)
    {
        targetForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
        targetForm.WindowState = FormWindowState.Normal;
    }
}
    private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e)
    {
        FullScreen fullScreen = new FullScreen();
        if (fullScreenMode == FullScreenMode.No)  // FullScreenMode is an enum
        {
            fullScreen.EnterFullScreenMode(this);
            fullScreenMode = FullScreenMode.Yes;
        }
        else
        {
            fullScreen.LeaveFullScreenMode(this);
            fullScreenMode = FullScreenMode.No;
        }
    }
我已经在另一个问题上提出了相同的答案,我不确定这个问题是否重复.(链接到另一个问题:如何在任务栏顶部全屏显示Windows窗体?)
对于menustrip问题,请尝试设置
MenuStrip1.Parent = Nothing
在全屏模式下,它应该消失.
退出fullscreenmode时,menustrip1.parent再次重置为表单,menustrip将再次正常.
您可以使用以下代码来适合您的系统屏幕,并且可以看到任务栏.
    private void Form1_Load(object sender, EventArgs e)
    {   
        // hide max,min and close button at top right of Window
        this.FormBorderStyle = FormBorderStyle.None;
        // fill the screen
        this.Bounds = Screen.PrimaryScreen.Bounds;
    }
无需使用:
    this.TopMost = true;
该行干扰alt+tab切换到其他应用程序.("TopMost"表示窗口保持在其他窗口的顶部,除非它们也标记为"TopMost".)
| 归档时间: | 
 | 
| 查看次数: | 119121 次 | 
| 最近记录: |