whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

49 Visitors Online


 
...adjust the Windowform to a TCanvas?
Autor: Iman Biglari
[ Print tip ]  

Tip Rating (3):  
     


{

 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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners