C# WinForm进入全屏模式
我有C# WinForm进入全屏模式,c#,winforms,C#,Winforms,我有WinForm应用程序,我想进入全屏模式并删除所有栏和任务栏。 我是这样做的: this.WindowState = FormWindowState.Maximized; this.FormBorderStyle = FormBorderStyle.None; this.TopMost = true; 顶部栏实际上是隐藏的,但Windows任务栏仍然可见。 你知道会有什么问题吗?重新排序行以最大化表单后,将使用FormBorderStyle标记。无和最顶部 this.FormBorderS
WinForm
应用程序,我想进入全屏模式并删除所有栏和任务栏。
我是这样做的:
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
顶部栏实际上是隐藏的,但Windows任务栏仍然可见。
你知道会有什么问题吗?重新排序行以最大化表单后,将使用FormBorderStyle标记。无和最顶部
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
您需要对语句重新排序,请尝试:
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
全屏运行您可以使用此方法
private void Form1_Load(object sender, EventArgs e)
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
要隐藏任务栏
,只需将该类添加到您的项目中即可。它可以按您的预期工作
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();
把上面的两行调换一下,还是不行