domingo, 7 de outubro de 2012

Faixa de Notícias

Essa função tem com o intuito ter uma faixa de notícias, passando na tela.

Primeiro, precisaremos de um label, que colocarei o nome de lblNoticias e um timer que colocarei o nome TimerNoticia;

No TimerNoticia coloque o valor de "interval" para 100, mas caso ache muito rápido é só aumentar esse valor;

Você pode colocar o valor da opção "visible" do HorzScrollBar para "false";

Caso você utilize uma image como fundo e está esteja com o Align colocado para alClient, então você deverá colocar a seguinte linha de código no procedimento OnResize do Form:
    
   Image1.Constraints.MaxWidth := Self.Width - 8;


Agora vamos ao que interessa, o código está preparado para rodar no caso de você pegar o que quer deixar como notícia no banco de dados, e então caso não tenha nada irá procurar no banco de 30 em 30 segundos, esse é o código para rodar a faixa de notícias:

procedure TForm1.TimerNoticiaTimer(Sender: TObject);
begin
   DoubleBuffered := True;

   if lblNoticias.Visible then
   begin
      lblNoticias.Left := lblNoticias.Left - 30;
   end;

   If ((lblNoticias.Left + lblNoticias.Width) <= 15) then
   begin
      lblNoticias.Caption := 'TESTE DE NOTÍCIAS';

      if (lblNoticias.Caption <> EmptyStr) then
      begin
         lblNoticias.Left := Self.Width + 1;
         lblNoticias.Caption := trim(lblNoticias.Caption) + ' *';
         TimerNoticia.Enabled := True;
         lblNoticias.Visible := True;
         TimerNoticia.Interval := 100;
      end
      else
      begin
         lblNoticias.Visible := False;
         TimerNoticia.Interval := 30000;
      end;
   end;
end;

Nenhum comentário:

Postar um comentário