Fantius
Fantius

Reputation: 3862

How can I control the border thickness and color on Windows Forms?

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)

Upvotes: 3

Views: 6609

Answers (2)

Michael A. McCloskey
Michael A. McCloskey

Reputation: 2411

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

Upvotes: 2

MusiGenesis
MusiGenesis

Reputation: 75296

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).

Upvotes: 3

Related Questions