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

Rounding control corners

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.