Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Contador de Apertura de Formulario (https://www.clubdelphi.com/foros/showthread.php?t=88338)

Claudio1996 22-05-2015 02:47:50

Contador de Apertura de Formulario
 
holaa .. buenas soy nuevo en esta pagina.. y tenia una duda acerca de como puedo crear un contador de 5 segundos a 0 y despues que me abra otro form ...creo que se puede hacer con un Timer y TLabel pero me podrian dar algunos ejemplos por favor..:confused::confused:

ecfisa 22-05-2015 06:05:32

Hola Claudio1996, bienvenido a Club Delphi :)

Como es costumbre con los nuevos miembros, te invitamos a leer nuestra guía de estilo.

Código Delphi [-]
uses Unit2;

var
  Contador : Integer = 5;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Label1.Caption := '5';
  with Timer1 do
  begin
    Enabled  := False;
    Interval := 1000; // ms.
    Enabled  := True;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Dec( Contador );
  Label1.Caption := IntToStr( Contador );
  if Contador = 0 then
  begin
    Timer1.Enabled := False;
    if not Assigned( Form2 ) then
      Form2 := TForm2.Create( Self );
    Form2.Show; // ( ó Form2.ShowModal; )
    //...
  end
end;

Saludos :)

AgustinOrtu 22-05-2015 06:10:45

Hola Claudio, a ver si este ejemplo te ayuda

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
    if not(Timer1.Enabled) then
    begin
        // el evento OnTimer se disparará a los 5 segundos de activar el timer
        Timer1.Interval := 5 * MSecsPerSec;
        Timer1.Enabled := True;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    Timer1.Enabled := False;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    Timer1.Enabled := False;
    with TForm2.Create(NIL) do
    begin
        ShowModal;
        Free;
    end;
end;

PD: Se me adelanto ecfisa :)

No deberia ir en otro foro esto?? Creo que no tiene mucho que ver con internet :D

Casimiro Notevi 22-05-2015 09:40:03

Lo he movido a "Varios", y para otra vez procura poner un título descriptivo a tu pregunta, gracias y bienvenido :)

nlsgarcia 22-05-2015 11:08:55

Claudio1996,

Cita:

Empezado por Claudio1996
...como puedo crear un contador de 5 segundos a 0 y despues que me abra otro form...

¡Bienvenido al Club Delphi! :D

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Count : Integer;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   Timer1.Interval := 100;
   Count := 5;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   Timer1.Interval := 1000;
   if (Count > 0) then
   begin
      Label1.Caption := IntToStr(Count);
      Dec(Count);
   end
   else
   begin
      Timer1.Enabled := False;
      Form2.Show;
   end;
end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Implementa un contador de 5 segundos para la salida de un formulario, como se muestra en la siguiente imagen:



Espero sea útil :)

Nelson.


La franja horaria es GMT +2. Ahora son las 10:52:55.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi