Mega Code Archive

 
Categories / Delphi / Graphic
 

Adjust the Windowform to a TCanvas

Title: adjust the Windowform to a TCanvas? { When youu need a form like a tree or something else what do you do? Windows provides the CreateRoundRectRegion() function that just cuts the edges of your form. If you want to do something else, you need to completely draw your region in a HDC (TCanvas) while Windows looks on your hand to learn it. After this, you can set the new region to your form using the 'SetWindowRgn()' function. And how to do this? Here you will find a simple example that just gives some text and sets the region like it. Expand it by your mind! } var Form1: TForm1; HRgn: THandle; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var s: string; begin DeleteObject(HRgn); s := InputBox('Region Text', 'Please enter some text to set to the region', 'CoolRgn'); BeginPath(Canvas.Handle); with Canvas do begin Font.Name := 'Comic Sans MS'; Font.Size := 64; Font.Style := [fsBold]; TextOut(0, 0, s); end; EndPath(Canvas.Handle); HRgn := PathToRegion(Canvas.Handle); SetWindowRgn(Handle, HRgn, True); button1.Visible := False; Color := clRed; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin DeleteObject(HRgn); end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then begin ReleaseCapture; SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); end; end;