当我运行C# WinForms应用程序时,如何隐藏Windows任务栏?
我尝试了一些代码,但它在最大化视图中打开并显示任务栏。
你有任何示例代码或建议吗?
当我运行C# WinForms应用程序时,如何隐藏Windows任务栏?
我尝试了一些代码,但它在最大化视图中打开并显示任务栏。
你有任何示例代码或建议吗?
只需将这个类添加到您的项目中即可。它会按照您的预期工作。
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();
Shell_SecondaryTrayWnd
。我认为您应该能够相应地调整上面的代码。请记住,在旧系统上或者如果没有第二个屏幕存在时,它可能为 null
。 - Christoph Meißner您需要按照以下方式从属性设置WinForms应用程序
private void Form1_Load(object sender, EventArgs e)
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
您需要使用P/INVOKE
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
int hwnd = FindWindow("Shell_TrayWnd","");
ShowWindow(hwnd,SW_HIDE);
ShowInTaskbar = false;
- Altivo