After two of the above interface development, we use the Windows Hook technology, the system has successfully intercepted the message of the form, and added their own event handlers, this article is through our processing of these messages, the first step to set the style of the form and region of the form.
Region is a very important concept for a form, which is the area that Windows assigns to the form, so our first step is to design our form region according to our needs. For Windows Form region settings, the stylechanged,showwindow,size,windowposchanged in the WndProc is likely to be used. All of these methods are modified for the style of the form or the size of the form, so we have to deal with these messages as well.
First we create a class to set the display of the form, named SkinAppearance.cs, in which I added a method called Setregion, and the parameter setting became our form skinningform. The code for Setregion is as follows:
/// <summary>
/// Set SkinningForm Region
/// </summary>
/// <param name="from">form to set region</param>
public void SetRegion(SkinningForm form)
{
// Check Form
if (form == null)
{
return;
}
// Get Form Size
Size size = form.Size;
// Set Color Size
Size cornerSize = new Size(90, 90);
// Create Region Handle
IntPtr hRegion = NativeMethod.CreateRoundRectRgn(0, 0, size.Width + 1, size.Height + 1, cornerSize.Width, cornerSize.Height);
Region region = Region.FromHrgn(hRegion);
// Set Region
form.Region = region;
region.ReleaseHrgn(hRegion);
}
So we set up our form style, where cornersize I set the larger, so the effect of the display is more obvious. The form shown is as follows:
This is a very ugly display, because we haven't done any other painting on the form yet. Of course we can do other things with the display of the form in this way. The next article will use GDI + to paint the form, primarily to design the border of the form.