Hide Start Button and TaskBar in Win7 or WinXP by Using C#
2016-05-16 16:19
1036 查看
If we expect that a winform program is shown in full screen mode without the title bar, the start button and the taskbar, we can use the following codes:
I tried to use such codes in Win7. In most cases this method can work. Occasionally the start button and taskbar are shown. This phenomenon is annoying. On Stack Overflow website a programmer suggested using the following codes:
It's a trick to assign Normal to WindowState firstly. The start button and taskbar are shown with a lower probability. This method seems to be better in my computer.
When I tried to create another process in the C# winform program, the new process would launch a new program window. When the screen switched to the new window, the start button and taskbar were show again. I searched the solution to avoiding this over
the internet, and found there was a good way to hide start button and taskbar in Visual C++. The code snippet is as follows:
A direct way in C# couldn't be found. So I thought the ultimate way in C# was to invoke Windows API in the similar way. I created a file named by 'HideTaskBarAndStartButton.cs'. Its content is as follows:
When you want to hide start button and the taskbar in C#, you can use the following codes:
In Win7:
In WinXP:
When you want to retrieve start button and the taskbar, you can use the following codes:
In Win7:
In WinXP:
private void Form1_Load(object sender, EventArgs e) { this.SetVisibleCore(false); this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; this.SetVisibleCore(true); }
I tried to use such codes in Win7. In most cases this method can work. Occasionally the start button and taskbar are shown. This phenomenon is annoying. On Stack Overflow website a programmer suggested using the following codes:
private void Form1_Load(object sender, EventArgs e) { this.SetVisibleCore(false); this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Normal; this.WindowState = FormWindowState.Maximized; this.SetVisibleCore(true); }
It's a trick to assign Normal to WindowState firstly. The start button and taskbar are shown with a lower probability. This method seems to be better in my computer.
When I tried to create another process in the C# winform program, the new process would launch a new program window. When the screen switched to the new window, the start button and taskbar were show again. I searched the solution to avoiding this over
the internet, and found there was a good way to hide start button and taskbar in Visual C++. The code snippet is as follows:
/**********************************************************/ void HideStartButtonInWin7(bool bHide) /* Parameter: */ /* bHide -- true hide start button in Windows 7 */ /* -- false show start button in Windows 7 */ { int nCmdShow; HWND hWnd; hWnd = FindWindow(_T("Button"),NULL); if(bHide == true) { nCmdShow = SW_HIDE; } else { nCmdShow = SW_SHOW; } ShowWindow(hWnd,nCmdShow); } /**********************************************************/ void HideStartButtonInWinXp(bool bHide) /* Parameter: */ /* bHide -- true hide start button in Windows XP */ /* -- false show start button in Windows XP */ { int nCmdShow; if(bHide == true) { nCmdShow = SW_HIDE; } else { nCmdShow = SW_SHOW; } ShowWindow(GetDlgItem(FindWindow(_T("Shell_TrayWnd"), NULL),0x130), nCmdShow); //0x130 is ID of start button in WinXP } /**********************************************************/ void HideTaskBar(bool bHide) /* Parameter: */ /* bHide -- true hide windows taskbar */ /* -- false show windows taskbar */ { int nCmdShow; HWND hWnd; hWnd = FindWindow(_T("Shell_TrayWnd"),NULL); if(bHide == true) { nCmdShow = SW_HIDE; } else { nCmdShow = SW_SHOW; } }
A direct way in C# couldn't be found. So I thought the ultimate way in C# was to invoke Windows API in the similar way. I created a file named by 'HideTaskBarAndStartButton.cs'. Its content is as follows:
/************************************************** * Author: HAN Wei * Author's blog: http://blog.csdn.net/henter/ * Date: May 16th, 2016 * Description: demonstrate how to hide and retrive * taskbar and start button in WinXp and Win7 **************************************************/ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace HideTaskBarAndStartButtonTools { class HideAndRetrive { [DllImport("user32.dll")] private static extern IntPtr FindWindow(string ClassName, string WindowName); [DllImport("user32.dll")] private static extern int ShowWindow(IntPtr WindowHandle, int nCmdShow); [DllImport("user32.dll")] private static extern IntPtr GetDlgItem(IntPtr WindowHandle, int nIDDlgItem); const int SW_HIDE = 0; const int SW_SHOW = 5; /**********************************************************/ /* HideStartButtonInWin7 * Parameter * bHide -- true hide start button in Win7 * -- false retrieve start button in Win7 */ /**********************************************************/ public static void HideStartButtonInWin7(bool bHide) { int nCmdShow; IntPtr hWnd; hWnd = FindWindow("Button", null); if (bHide == true) { nCmdShow = SW_HIDE; } else { nCmdShow = SW_SHOW; } ShowWindow(hWnd, nCmdShow); } /**********************************************************/ /* HideStartButtonInWinXP * Parameter * bHide -- true hide start button in Win7 * -- false retrieve start button in Win7 */ /**********************************************************/ public static void HideStartButtonInWinXP(bool bHide) { int nCmdShow; if (bHide == true) { nCmdShow = SW_HIDE; } else { nCmdShow = SW_SHOW; } ShowWindow(GetDlgItem(FindWindow("Shell_TrayWnd", null), 0x130), nCmdShow); //0x130 is ID of start button in WinXP } /**********************************************************/ /* HideTaskBar * Parameter * bHide -- true hide windows taskbar * -- false retrieve windows taskbar */ /**********************************************************/ public static void HideTaskBar(bool bHide) { int nCmdShow; IntPtr hWnd; hWnd = FindWindow("Shell_TrayWnd", null); if (bHide == true) { nCmdShow = SW_HIDE; } else { nCmdShow = SW_SHOW; } ShowWindow(hWnd, nCmdShow); } } }
When you want to hide start button and the taskbar in C#, you can use the following codes:
In Win7:
using HideTaskBarAndStartButtonTools; HideAndRetrive.HideStartButtonInWin7(true); HideAndRetrive.HideTaskBar(true);
In WinXP:
using HideTaskBarAndStartButtonTools; HideAndRetrive.HideStartButtonInWinXP(true); HideAndRetrive.HideTaskBar(true);
When you want to retrieve start button and the taskbar, you can use the following codes:
In Win7:
using HideTaskBarAndStartButtonTools; HideAndRetrive.HideStartButtonInWin7(false); HideAndRetrive.HideTaskBar(false);
In WinXP:
using HideTaskBarAndStartButtonTools; HideAndRetrive.HideStartButtonInWinXP(false); HideAndRetrive.HideTaskBar(false);
相关文章推荐
- C# DataGridView的单元格输入限制,并提示用户 数字,小数点
- C# Hashtable类
- C#.net开发 List与DataTable相互转换
- 【C#公共帮助类】 Log4net 帮助类
- C#实现通过模板自动创建Word文档的方法
- C#生成World文档
- 将C#文档注释生成.chm帮助文档
- C# 调用中通快递查询物流轨迹接口
- C#学习笔记之File类
- C#详解反射
- [转载]C#4.0中的可选参数和命名参数
- 【205】C#实现远程桌面访问
- C# using
- c# 使用递归 循环遍历导航树结构 并解析
- 研华IO卡C#调用
- C# 使用ColorMatrix时各种效果的参数
- C# Windows API
- C#和.NET框架和术语
- C#中Invoke 和 BeginInvoke 的区别
- C#多线程的异步委托/调用