Browse DevX
Sign up for e-mail newsletters from DevX


Don't Be Square: Creating Non-Rectangular Windows with .NET : Page 3

If you're tired of the same old rectangular boring user interfaces in your Windows programs and prefer the funky shapes of applications such as Windows Media Player 9, follow this step-by-step guide to take your applications where they have never been before.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Masking the Form
After completing the mask image, you need to create your windows application. You'll "skin" the application's main window with the mask. Launch Visual Studio.NET and create a new Windows Application project. Visual Studio creates a standard, simple, one-form, application with a rectangular form called Form1.

You're going to jazz that form up a bit. First, you have to remove the borders of the form, so set the formBorderStyle property to None. That will get rid of the form outline and the sizing handles. In this case you don't want your users to resize your form. Next, you set the BackgroundImage property to the path to your mask file. You may need to resize your form to fit the mask. Note that setting the BackgroundImage property makes your image act as wallpaper on the form—the background image repeats as a pattern if the form is wider or taller than the image (see Figure 4).

Figure 4. Image Wallpaper: Your mask image acts as wallpaper on the form, repeating if the image and form sizes don't match.
Resize your form so that you see a single instance of your mask, eliminating any repeating patterns. Next, you need to tell the form that you want the white part to be transparent, so that you can see through it when running the application. You do this by setting the TransparencyKey property to white.

If you run your application now, you'll see a beautiful, non rectangular wooden-looking form on the screen. But wait a minute! Because there's no Windows title bar at the top, you can't click 'x' to close it, and you can't move it around. It's just stuck there. Fortunately, you can close it with ALT-F4. In the next section you'll see how to add dragging functionality as well as self-closing capability.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date