Canvas - pintando um bitmap dentro de um texto igual ao powerclip do corel |
Top Previous Next |
|
object Form1: TForm1 Left = 97 Top = 202 Width = 843 Height = 179 Caption = 'Texto com efeitos especiais' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate OnDestroy = FormDestroy OnMouseDown = FormMouseDown OnPaint = FormPaint PixelsPerInch = 96 TextHeight = 13 end
-------------------------------------------------------------------------
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type TForm1 = class(TForm) procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormPaint(Sender: TObject); private FRegion : HRGN; FBitmap : TBitmap; end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if PtInRegion(FRegion,X,Y) then ShowMessage('Clicou no texto'); end;
procedure TForm1.FormDestroy(Sender: TObject); begin Brush.Bitmap := nil; FBitmap.Free; DeleteObject(FRegion); end;
procedure TForm1.FormCreate(Sender: TObject); begin FBitmap := TBitmap.Create; FBitmap.LoadFromFile('H:\Delphi\Imagens\Botoes\NovoIcon.bmp'); // seta tamanho do fonte Font.Name := 'Arial'; Font.Size := 64; Font.Style := [fsBold]; with Canvas do begin // modo transparente para não desenhar quadro em volta do texto SetBKMode(Handle,TRANSPARENT); // inicia o caminho BeginPath(Handle); // desenha o texto TextOut(20,20,'Flavio Junior'); EndPath(Handle); Brush.Bitmap := FBitmap; // seta Brush para o bitmap carregado end; FRegion := PathtoRegion(Canvas.Handle); end;
procedure TForm1.FormPaint(Sender: TObject); begin Font.Name := 'Arial'; Font.Size := 64; Font.Style := [fsBold]; with Canvas do begin // modo transparente para não desenhar quadro em volta do texto SetBKMode(Handle,TRANSPARENT); // inicia o caminho BeginPath(Handle); // desenha o texto TextOut(20,20,'Flavio Junior'); EndPath(Handle); Brush.Bitmap := FBitmap; FillPath(Handle); // seta Brush para o bitmap carregado end; end;
end. |