c# - WinForm进入全屏模式

标签 c# winforms

<分区>

我有 WinForm 应用程序,我想进入全屏模式并删除所有栏和任务栏。 我这样做了:

this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;

顶部栏确实隐藏了,但 Windows TaskBar 仍然可见。 知道有什么问题吗?

最佳答案

全屏运行你可以使用这个方法..

private void Form1_Load(object sender, EventArgs e)
{
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

要隐藏 TaskBar 只需将此类添加到您的项目中。它会按您预期的那样工作。

using System;
using System.Runtime.InteropServices;

public class Taskbar
{
    [DllImport("user32.dll")]
    private static extern int FindWindow(string className, string windowText);

    [DllImport("user32.dll")]
    private static extern int ShowWindow(int hwnd, int command);

    [DllImport("user32.dll")]
    public static extern int FindWindowEx(int parentHandle, int childAfter, string className, int windowTitle);

    [DllImport("user32.dll")]
    private static extern int GetDesktopWindow();

    private const int SW_HIDE = 0;
    private const int SW_SHOW = 1;

    protected static int Handle
    {
        get
        {
            return FindWindow("Shell_TrayWnd", "");
        }
    }

    protected static int HandleOfStartButton
    {
        get
        {
            int handleOfDesktop = GetDesktopWindow();
            int handleOfStartButton = FindWindowEx(handleOfDesktop, 0, "button", 0);
            return handleOfStartButton;
        }
    }

    private Taskbar()
    {
        // hide ctor
    }

    public static void Show()
    {
        ShowWindow(Handle, SW_SHOW);
        ShowWindow(HandleOfStartButton, SW_SHOW);
    }

    public static void Hide()
    {
        ShowWindow(Handle, SW_HIDE);
        ShowWindow(HandleOfStartButton, SW_HIDE);
    }
}

用法:

Taskbar.Hide();

关于c# - WinForm进入全屏模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19228090/

相关文章:

c# - 如何在 C# 中刷新表单?

winforms - F# : what is the deal with the flicker? 中的双缓冲

c# - 使用for循环添加任务用于创建限制并发的任务调度程序

c# - 根据条件从 DataTable 中删除行

c# - 将自定义属性绑定(bind)到 TextBox UWP

c# - 澄清使用匿名方法从单独的线程更新 GUI

c# - 为什么 .Net Framework 基类型不包含 IConvertible 方法的实现?

c# - 洪水填充算法导致堆栈溢出

c# - 如何消除动画撕裂?

c# - Winforms中如何获取被点击的ListView单元格?