Interface Development (iii)---Set the region of a form

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.