Display an Irregularly Shaped Window

Problem

You want to create a non-rectangular form.

Solution

Create a new Region object that has the shape you want for the form, and assign it to the Form.Region property.

Discussion

To create a non-rectangular form, you first need to define the shape you want. The easiest approach is to use the System.Drawing.Drawing2D.GraphicsPath object, which can accommodate any combination of ellipses, rectangles, and closed curves. You can add shapes to a GraphicsPath instance using methods such as AddEllipse, AddRectangle, and AddClosedCurve. Once you are finished defining the shape you want, you can create a Region object from this GraphicsPath—just submit the GraphicsPath in the Region class constructor. Finally, you can ...

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.