Dicas - Criando Label em 3D

Veremos nesta dica como criar Labels capazes de exibir textos em 3D.

Criando Labels em 3D

 

Veremos nesta dica como criar labels capazes de exibir textos em 3D. Os labels deste exemplo terão dois efeitos possíveis: destacados do formulário, com um pequeno sombreamento por trás dele ('Raised')  ou 'mergulhados" para dentro do formulário ('Lowered'). O procedimento responsável por estes efeitos é muito simples e útil. Este procedimento poderá facilmente ser personalizado para aceitar mais parâmetros. O resultado deste exemplo em execução é o seguinte:

 

Para testá-lo, inicie uma nova aplicação e insira no formulário dois componentes do tipo botão.  Configure as propriedades caption dos botões da seguinte forma:

 

Button1:Button2:

 

caption = Loweredcaption = Raised

 

Escreva o código abaixo na seção Implementation:

 

procedure Create3DLabel (oForm : TWinControl; const sText: string = 'Delphi';

  iTop : Integer = 0; iLeft : Integer = 0;

  iDepth: Integer = 3;

  sFontName: string = 'Arial';

  iFontSize : Integer = 10;

  sLookingType : String = 'Raised';

  sCorLabel : TColor = clBlack;

  sCor3D : TColor = clWhite);

var

  oLabel1 : TLabel;

  oLabel2 : TLabel;

begin

  oLabel1 := TLabel.Create(oForm);

  oLabel1.Parent := oForm;

  oLabel1.Transparent := True;

  oLabel1.Font.Name := sFontName;

  oLabel1.Font.Size := iFontSize;

  oLabel1.Caption := sText;

 

  oLabel2 := TLabel.Create(oForm);

  oLabel2.Parent := oForm;

  oLabel2.Transparent := True;

  oLabel2.Font.Name := sFontName;

  oLabel2.Font.Size := iFontSize;

  oLabel2.Caption := sText;

  if sLookingType = 'Lowered' then

  begin

    oLabel1.Top := iTop + iDepth;

oLabel1.Left := iLeft + iDepth;

oLabel1.Font.Color := sCor3D;

oLabel2.Font.Color := sCorLabel;

    oLabel2.Top := iTop;

oLabel2.Left := iLeft;

oLabel2.BringToFront;

  end;

 

  if sLookingType = 'Raised' then

  begin

    oLabel1.Top := iTop - iDepth;

oLabel1.Left := iLeft - iDepth;

oLabel1.Font.Color := sCorLabel;

oLabel1.BringToFront;

 

oLabel2.Top := iTop;

oLabel2.Left := iLeft;

oLabel2.Font.Color := sCor3D;

  end;

end;

 

Adicione dois botões ao formulário e no evento OnClick de cada um escreva o seu respectivo código como mostrado a seguir:

 

procedure TForm1.Button1Click(Sender: TObject);

var

  strCaption, strFonte : string;

  intTamanhoFonte, intPosEsquerda, intPosCima : integer;

  strCorLabel : TColor;

const

  str3DParaDentro : string = 'Lowered';

  strCorFundo : TColor = clWhite;

  intProfDentro : integer = 1;

begin

  strCaption := 'Hello World';

  strFonte := 'Times New Roman';

  intTamanhoFonte := 24;

  strCorLabel := clBlue;

  intPosEsquerda := 10;

  intPosCima := 10;

  Create3DLabel (TWinControl(self), strCaption, intPosCima, intPosEsquerda,

intProfDentro, strFonte, intTamanhoFonte, str3DParaDentro,

strCorLabel, strCorFundo);

end;

 

procedure TForm1.Button2Click(Sender: TObject);

var

  strCaption, strFonte : string;

  intTamanhoFonte, intPosEsquerda, intPosCima : integer;

  strCorLabel : TColor;

const

  str3DParaFora : string = 'Raised';

  strCorFundo : TColor = clBlack;

  intProfFora : integer = 2;

begin

  strCaption := 'Hello World';

  strFonte := 'Times New Roman';

  intTamanhoFonte := 24;

  strCorLabel := clRed;

  intPosEsquerda := 50;

  intPosCima := 50;

  Create3DLabel (TWinControl(self), strCaption, intPosCima, intPosEsquerda,

    intProfFora, strFonte, intTamanhoFonte, str3DParaFora,

strCorLabel, strCorFundo);

end;

 

por Edison Costa

webmaster@clubedelphi.com.br

Ebook exclusivo
Dê um upgrade no início da sua jornada. Crie sua conta grátis e baixe o e-book

Artigos relacionados