Form for drawing rounded rectangle in Delphi

Source: Internet
Author: User

 

Form for creating a rounded rectangle:

01. Procedure tportform. formcreate (Sender: tobject );
02. var HR: thandle;
03. Begin
04. HR: = createroundrectrgn (0, 0, width, height, 20, 20 );
05. setjavaswrgn (handle, HR, true );
06. end;

If you do not want an external box, use:

01. Procedure tportform. formcreate (Sender: tobject );
02. var HR: thandle;
03. Begin
04. HR: = createroundrectrgn (1, 1, width-2, height-2, 20, 20 );
05. setjavaswrgn (handle, HR, true );
06. end;

Because of the window made by the first code, there is no border in the rounded corner. Use the following code to create a border:

01. Procedure tform1.formpaint (Sender: tobject );
02. var
03. DC: HDC;
04. Pen: Hpen;
05. oldpen: Hpen;
06. oldbrush: hbrush;
07. Begin
08. DC: = getwindowdc (handle );
09. Pen: = createpen (ps_solid, 1, clgray );
10. oldpen: = SelectObject (DC, pen); // load the custom paint brush and save the original paint brush.
11. oldbrush: = SelectObject (DC, getstockobject (null_brush); // load an empty paint brush and save the original paint brush
12. roundrect (DC, 0, 0, width-1, height-1, 21,21); // draw a border
13. SelectObject (DC, oldbrush); // load the original paint brush
14. SelectObject (DC, oldpen); // load the original paint brush
15. deleteobject (PEN );
16. releasedc (handle, DC );
17. end;

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.