type<br> TForm1 = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> procedure FormPaint(Sender: TObject);<br> procedure FormResize(Sender: TObject);<br> private<br> { Private declarations }<br> procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;<br> protected<br> procedure CreateParams(var Params: TCreateParams); override; <br> public<br> { Public declarations }<br> end;<br><br>procedure TForm1.CreateParams(var Params: TCreateParams);<br>begin<br> inherited CreateParams(Params);<br> Params.Style := WS_POPUP or WS_SIZEBOX;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> hr: HRGN;<br>begin<br> hr := CreateRoundRectRgn(0, 0, Width, Height, 20, 20);<br> SetWindowRgn(Handle, hr, True);<br> DeleteObject(hr);<br>end;<br><br>procedure TForm1.FormPaint(Sender: TObject);<br>var<br> C: TCanvas;<br>begin<br> C := TControlCanvas.Create;<br> try<br> C.Handle := GetWindowDC(Handle);<br> C.Brush.Style := bsClear;<br> C.Pen.Color := clBlue;<br> C.Pen.Width := 3;<br> C.RoundRect(1, 1, Width-2, Height-2, 20, 20);<br> finally<br> C.Free; // TControlCanvas.FreeHandle会ReleaseDC<br> end;<br>end;<br><br>procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);<br>begin<br> inherited;<br> if Message.Result = HTCLIENT then Message.Result := HTCAPTION;<br>end;<br><br>procedure TForm1.FormResize(Sender: TObject);<br>var<br> hr: HRGN;<br>begin<br> hr := CreateRoundRectRgn(0, 0, Width, Height, 20, 20);<br> SetWindowRgn(Handle, hr, True);<br> DeleteObject(hr);<br> Invalidate;<br>end;