
Tips for shaped forms and controlsIt's possible to create shaped windows that take their outline from a region. Here are few tips that will save you a lot of head scratching later. The region can be created from a GraphicsPath object and can be complex including taking the shape of text glyphs and other drawing commands such as cardinal splines and Bezier curves. The outline shape of a control can be modified at any time by putting a new region into the Region property. For controls that change shape dynamically you need to be aware that the old region will be disposed of by the control when it's replaced. Therefore, if you do something clever like build your regions and keep them for the lifetime of the control then you'll find that the second time you try to use any given region an exception will occur because you tried to use a region that had been disposed of. Use a clone of the region instead to prevent this from happening. When drawing the background for a complex region remember that regions are masks that rely on pixel boundaries whereas drawing, especially antialiased drawings, are pixel resolution independent and so you may find odd effects like strange halos around text or drawn lines. When drawing for shaped controls try to use a non-antialiased drawing mode wherever possible. Forms cannot have the region assigned in the constructor. Use the OnLoad handler instead. Window regions include the non-client areas so when creating a region for a form you need to be aware that an offset might be needed to prevent non-client areas being included in your shaped window. For example, if you create a shaped window from a standard form you need to have X and Y offsets that don't include the title bar or the sizing grips. This page will get updated as more tips occur to me...
Return to Windows Forms Tips and Tricks Copyright Ramuseco Limited 2004. All rights reserved.
|