2013-09-26 72 views

回答

4

您需要使用的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); 

我希望幫助

2

您需要從屬性設置WinForms應用程序像下面

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

這不包括任務欄,但它禁止它對幾乎所有的功能 –

14

剛將此類添加到您的項目中。它按預期工作。

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(); 
+1

存在工程隱藏任務欄任何方式在第二臺顯示器 –

相關問題