1. Home
  2. Computing & Technology
  3. Delphi Programming

Rounding control corners

By Zarko Gajic, About.com

Here's how to "draw" controls with rounded corners.

For testing drop one TEdit, TPanel and TMemo on a form.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure DrawRounded(Control: TWinControl) ;
var
   R: TRect;
   Rgn: HRGN;
begin
   with Control do
   begin
     R := ClientRect;
     rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, 20, 20) ;
     Perform(EM_GETRECT, 0, lParam(@r)) ;
     InflateRect(r, - 4, - 4) ;
     Perform(EM_SETRECTNP, 0, lParam(@r)) ;
     SetWindowRgn(Handle, rgn, True) ;
     Invalidate;
   end;
end;


procedure TForm1.FormCreate(Sender: TObject) ;
begin
   // rounding Panel1
   DrawRounded(Panel1) ;

   // rounding Memo1
   Memo1.BorderStyle := bsNone;
   DrawRounded(Memo1) ;

   // rounding Edit1
   Edit1.BorderStyle := bsNone;
   DrawRounded(Edit1) ;

end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to call the Find dialog in WebBrowser
« How to sort items in a TList object

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2003 Delphi Tips
  7. Rounding control corners

©2009 About.com, a part of The New York Times Company.

All rights reserved.