Make a Borderless Form Movable

Problem

You want to create a borderless form that can be moved. This might be the case if you are creating a custom window that has a unique look (for example, for a visually rich application such as a game or a media player).

Solution

Create another control that responds to the MouseDown, MouseUp, and MouseMove events and programmatically moves the form.

Discussion

Borderless forms omit the title bar portion, which makes it impossible for them to be moved by the user. You can compensate for this shortcoming by adding a control to the form that serves the same purpose.

For example, Figure 11-16 shows a form that includes a label for dragging. When the label is clicked, the code sets a form-level flag to indicate it’s in ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.