本文介绍了隐藏任务栏在WinForms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何隐藏在Windows任务栏,当我运行我的C#WinForms应用程序?
How can I hide the Windows taskbar when I run my C# WinForms application?
我尝试了一些代码,但它在任务栏最大化视图中打开。
I tried some code, but it opens in maximized view with the taskbar.
你有任何示例代码或建议
Do you have any sample code or suggestions?
推荐答案
的只需添加这个类到您的项目。它可以作为你预期的的
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();
这篇关于隐藏任务栏在WinForms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!