Delphi中绘制圆角矩形的窗体

 

制作圆角矩形的窗体:

01.procedure TPortForm.FormCreate(Sender: Tobject);
02.var hr :thandle;
03.begin
04.hr:=createroundrectrgn(0,0,width,height,20,20);
05.setwindowrgn(handle,hr,true);
06.end;


如果不要窗体外框,则使用:

01.procedure TPortForm.FormCreate(Sender: Tobject);
02.var hr :thandle;
03.begin
04.hr:=createroundrectrgn(1,1,width-2,height-2,20,20);
05.setwindowrgn(handle,hr,true);
06.end;


由于第一段代码做出来的窗口,圆角部份会没有边框,使用下面的代码做出边框:

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); //载入自定义的画笔,保存原画笔
11.OldBrush := SelectObject(DC, GetStockObject(NULL_BRUSH));//载入空画刷,保存原画刷
12.RoundRect(DC, 0, 0, Width-1, Height-1,21,21); //画边框
13.SelectObject(DC,OldBrush);//载入原画刷
14.SelectObject(DC,OldPen); // 载入原画笔
15.DeleteObject(Pen);
16.ReleaseDC(Handle, DC);
17.end;

你可能感兴趣的:(Form,Graphic)