首页  编辑  

让控件的边角圆滑起来?

Tags: /超级猛料/VCL/Control.控件使用开发和第三方控件/控件使用技巧/   Date Created:

show controls with rounded corners?

procedure MakeRounded ( 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 , - 5 , - 5 );

   Perform ( EM_SETRECTNP , 0 , lParam (@ r ));

   SetWindowRgn ( Handle , rgn , True );

   Invalidate ;

  end ;

end ;

procedure TForm1 . Button1Click ( Sender : TObject );

begin

  // TMemo:

 Memo1 . BorderStyle := bsNone ;

 MakeRounded ( Memo1 );

  // TEdit:

 Edit2 . BorderStyle := bsNone ;

 MakeRounded ( Edit2 );

  // TPanel:

 MakeRounded ( Panel1 );

  // TStaticText:

 MakeRounded ( StaticText1 );

  // TForm

 Form1 . BorderStyle := bsNone ;

 MakeRounded ( Form1 );

end ;

img_21140.bmp (201.9KB)