(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