Control study-> obtain the circular form using the method of obtaining the path (for example, convert picturebox to a circle)

Source: Internet
Author: User

(1). Functions

Sometimes, due to the display effect, you need to change the shape of a widget.
In this example, the picturebox [] array is converted into a circle.

(2). Example Image

Initial image:

After the method is called, the image display effect is as follows:

(3 ).Code

Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;

Namespace chess game
{
/// <Summary>
/// Function: Convert all picturebox controls into circles
/// Feature: round the flag

/// </Summary>

Public class class7
{
[System. runtime. interopservices. dllimport ("GDI32")]
Private Static extern intptr beginpath (intptr HDC );
[System. runtime. interopservices. dllimport ("GDI32")]
Private Static extern int setbkmode (intptr HDC, int nbkmode );
Const int transparent = 1;
[System. runtime. interopservices. dllimport ("GDI32")]
Private Static extern intptr endpath (intptr HDC );
[System. runtime. interopservices. dllimport ("GDI32")]
Private Static extern intptr pathtoregion (intptr HDC );
[System. runtime. interopservices. dllimport ("GDI32")]
Private Static extern int ellipse (intptr HDC, int X1, int Y1, int X2, int Y2 );
[System. runtime. interopservices. dllimport ("USER32")]
Private Static extern intptr set1_wrgn (intptr hwnd, intptr hrgn, bool bredraw );
[System. runtime. interopservices. dllimport ("USER32")]
Private Static extern intptr getdc (intptr hwnd );
Public class7 ()
{
}
Public void maketopictureboxstocircle (picturebox [] Pb)
{
Intptr DC;
Intptr region;
For (INT I = 0; I <Pb. length; I ++)
{
Dc = getdc (Pb [I]. Handle );
Beginpath (DC );
Setbkmode (DC, transparent );
Ellipse (DC, 0, 0, Pb [I]. Width-3, Pb [I]. Height-2 );
Endpath (DC );
Region = pathtoregion (DC );
Setjavaswrgn (Pb [I]. Handle, region, false );
}
}
}
}

In fact, it not only turns a widget into a circle, but also a widget into any shape.

(4) Sample Code download

Http://www.cnblogs.com/files/chengking/draw a polygon (..rar

 

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.