⌘BABAKOV.NET Let's code!
100% [light] [ru]

Removing the Taskbar on .NET CF 2.0 (Making Full Screen) C#

Recently encountered a problem where FormWindowState.Maximized did not work everywhere. For example, it stopped working on one of my devices with Windows CE 6.0, and no amount of dancing helped. I spent a long time searching the internet, but found nothing in Russian. I eventually found a guide on an English-language website.

It worked for me!

The problem is solved by three functions from coredll.dll:

//Отображает тем или иным способом окно (в том числе и скрывает его).
[DllImport("coredll.dll", CharSet = CharSet.Auto)]
public static extern bool ShowWindow(int hwnd, int nCmdShow);

//Делает окно доступным либо недоступным (убрать с экрана либо показать).
DllImport("coredll.dll", CharSet = CharSet.Auto)]
public static extern bool EnableWindow(int hwnd, bool enabled);

//Находит нужное окно по наименованию.
[DllImport("coredll.dll")]
public static extern int FindWindow(string className, string windowName);



Don't forget to add InteropServices to your project:

using System.Runtime.InteropServices;



For reference, ShowWindow can take the following values:

SW_HIDE = 0
SW_SHOWNORMAL = 1
SW_NORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWMAXIMIZED = 3
SW_MAXIMIZE = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_FORCEMINIMIZE = 11
SW_MAX = 11



Now, in your project, remove the taskbar when loading the form like this:

int hid = FindWindow("HHTaskBar", "");
ShowWindow(hid, 0);
EnableWindow(hid, false);



After that, the taskbar will disappear, and to stretch the form to the remaining empty space, do this:

this.Width = Screen.PrimaryScreen.Bounds.Width;
this.Height = Screen.PrimaryScreen.Bounds.Height;
this.TopMost = true;



And don't forget to restore the taskbar when exiting the application:

int hid = FindWindow("HHTaskBar", "");
ShowWindow(hid, 5);
EnableWindow(hid, true);



And that's it!

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.