C# Programming > Miscellaneous

C# Windows 7 Style Form

Windows 7 Docking

One of the new features of the upcoming Windows 7 is the ability of applications to dock to different parts of the screen. Modifying a Windows Form in .NET to simulate the behavior of a Windows 7 application is not too difficult.

The Windows 7 style C# application will run in other versions of Windows. And to keep it simple, it will not be exactly like in Windows 7.


The first part of docking a Form in C# is capturing when the application is docked and when it is not. In Windows 7, dragging an application to one of the four sides of the screen docks the window to the appropriate edge. For our C# window, it will dock when dragged to either the left, right or top edges of the screen.

When the .NET Form is docked, we also want it to "stick" to the top, making it easy to drag the application horizontally while remaining docked to the sides.

Finally the original size of the Form should be restored when the window is dragged back into the center of the screen, like in Windows 7.

Window Messages

The behavior of a Windows 7 style Form is not complicated (although it is bug prone). There are two ways to achieve behavior, using C# Form Events or processing Form messages directly.

Events provide a cleaner implementation more consistent with .NET code. However events are triggered after internal window messages are processed. So in our case, if we want to adjust the movement of an application, there is going to be flickering.

In other to avoid window flickering, we are going to processes window messages by overriding WndProc in the C# Form. This gives us the ability to modify the window behavior before it is displayed to the screen. Thus the window will act smoothly.

The downside to overriding the WndProc is that the code is less clean, or at least it is not simple .NET code. Additionally it can cause conflicts with other operations that handle windows messages.

Window 7 Form

For our purposes the .NET Form will override the WndProc. The behavior is similar to that of application in Windows 7, but not exactly the same. I'll leave it to you to tweak the code for more accurate Windows 7 style Form in .NET.

Back to C# Article List