views:

624

answers:

2

I know that this can be controlled at the system level, but I want to override the system setting and have a certain appearance for only my application. I'm assuming there must be a Windows API function to control this because I've seen another windows app that does it.

(It is not necessary to go into the reasons why I should not do this)

+1  A: 

If you want a custom appearance for your application, I would just make my form borderless and handle everything myself, either by drawing on the form itself in the Paint event, or else moving controls around (panels etc.) in the Resize event. You have to handle things like dragging, resizing, closing/minimizing etc., but none of this is especially difficult.

Here is my answer to a similar question, which shows the basics of doing it yourself (it's for windows mobile, but it will work in regular windows too).

MusiGenesis
I started down this road after asking the question. I was hoping there was a better way. If I draw the stuff myself, can I still have windows do the resizing by firing off a start-resize message or something? Of not, I cannot replicate the dotted-line effect that is seen while a window is being resized (when the windows setting "Show window contents while dragging" is deactivated).
Fantius
Good point - I don't know about that. I just checked out iTunes (which in Windows is completely owner-drawn like what you're trying to do), and it shows a dotted-line outline while dragging, but interestingly it isn't the same dotted-line border as a normal Windows window, which means they're handling the outline themselves, also.
MusiGenesis
I think the outline would be relatively easy to implement yourself. In the mousedown event, you would pop up a second borderless form with a transparent background and a dotted-line border, and move that around until the mouseup event, and then move your real form to the new position.
MusiGenesis
+2  A: 

These outer elements of an applications window are collectively referred to as the windows "chrome" and are indeed rendered by the operating system. Various flags are used at the windows API level to controls certain aspects of each window instance (e.g. the existing of a control box, border, min/max buttons, etc.), but the border width for resizable windows is determined by a system setting to ensure uniformity and is not configurable on a window by window basis.

You can, in many instances, gain control over some of the aspects of your window not exposed by .NET by interacting with the windows API and it is beneficial to read the windows API documentation to determine just what is possible at that lower level. I suggest reading the documentation for CreateWindowEx as a starting point.

http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx

.NET allows you to change the FormBorderStyle property to select among no border, single pixel width border, and resizable (thick border). If you'd like to do something custom, you'll have to set the .NET border style to none, and then assume the responsibility for rendering the window chrome yourself. This entails rendering your own caption bar, min/max buttons, and window border. It's not a light undertaking, but many apps do it. It's a long way to go if all you really want is to control the border width.

This article goes into how one might approach this task in WPF, and may also be of use.

Window Chrome In WPF

Michael McCloskey
+1 except that this is a relatively light undertaking. Not usually worth it, but not difficult at all.
MusiGenesis