WinForm programming control in the use of small tips (splitter implementation of the window in the subregion, changing the shape of the button) __ programming

Source: Internet
Author: User

The primary role of the Splitter control is to partition the window and adjust the area size, for example: I want to divide the window into about two regions and adjust the proportions of two regions. The operation process is as follows:

1, a new window: Form1;

2. Add a Panel control Panel1 to the Form1 and set its Dock property to the Left,backcolor property set to blue;

3. Add a splitter control Splitter1 to the Form1 and set its Dock property to left;

4. Add a Panel control Panel2 in Form1 and set its Dock property to black Fill,backcolor property;

Second, WinForm programming often need to apply button control, sometimes we want to change the button shape, in fact, simply change the button shape is very simple, the following I want to talk about this method can be simply understood as, In a rectangular area, add a closed area surrounded by several segments, displaying only the enclosed area without displaying the area outside the enclosing area. To achieve this, we use a property region (enclosing area) of the button control, an event paint (drawing the shape).

Then, in the example above, we add a button button1 to the panel and set its Anchor property to Bottom,right. The Paint event is found in the Button1 event, which is called when the shape of the button1 is drawn when the program is run, so we simply add code to change the region property to change the shape of the button1. Add the code as follows:

  Using System.Drawing.Drawing2D;
        private void Button1_paint (object sender, PaintEventArgs e)
            GraphicsPath path = new GraphicsPath ();
            Path. AddLines (new point[] {new Point (2), new Point (+), new Point (X), new Point (X), new Point (M), new P Oint (+), new Point (2), new Point (X),});
            This.button1.Region = new Region (path);
This code is very well understood: first is to set a GraphicsPath type of path, and then add a few segments in this path (the origin of the coordinate system is the upper-left corner of the button1), the size of the button we set is 70, 36, in the coordinate system of the button1 in the lower right corner of the coordinates is (70,36), and then we are in this rectangular area to find 7 points around an arrow shape can be, and finally the Button1 region property to be assigned a value.

The effect is as shown in the following illustration:

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: 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.