was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

36 Visitors Online


 
...die Fensterform einem TCanvas anpassen?
Autor: Iman Biglari
[ Tip ausdrucken ]  

Tip Bewertung (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;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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