[WPF] Hide the “Window Buttons” (minimize, restore and close) and the icon of a window

No “Red-X”? Then I can’t close the window! How to achieve this reaction in WPF applications.

Even if it is not always the user friendliest way, there are situation in which you do no want the user to close a window using the “red X” in the upper right corner of a window’s non client area (sometimes only called “Close Button” 😉 ).

In most cases this behavior is expected from Dialogs which usually do not have “Minimize” and “Maximize” buttons. So it’s a common practice to hide the whole so called “System Menu”, “Control Box” or “System Bar”.

Windows Forms

It’s quite easy to do so in Windows Forms: Simply set the ControlBox property to false:

Read the rest of this entry »

Find out Size (and position) of the taskbar

What size is the taskbar on this computer? And where is it at all? This post has the answer.

A common problem is to find out the size and the location of the taskbar.

Almost as common as the problem is the following solution:

public static int GetTaskbarHeight()
    return Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;

At least, it is better than hardcoding the height in code. And it will work on lots of machines.

However, it has some really bad disadvantages:

Read the rest of this entry »