Progressbarlı Messagebox

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
csyasar
Üye
Mesajlar: 646
Kayıt: 25 Şub 2004 10:14
Konum: Tokat

Progressbarlı Messagebox

Mesaj gönderen csyasar »

Kod: Tümünü seç

procedure TForm1.Button1Click(Sender: TObject) ;
var
   AMsgDialog : TForm;
   AProgressBar : TProgressBar;
   ATimer : TTimer;
begin
   AMsgDialog := CreateMessageDialog('Quickly! Answer Yes or No!', mtWarning, [mbYes, mbNo]) ;
   AProgressBar := TProgressBar.Create(AMsgDialog) ;
   ATimer := TTimer.Create(AMsgDialog) ;
   with AMsgDialog do
   try
    Tag := 10; //seconds!

    Caption := 'You have 10 seconds';
    Height := 150;

    with AProgressBar do begin
     Name := 'Progress';
     Parent := AMsgDialog;
     Max := AMsgDialog.Tag; //seconds
     Step := 1;
     Top := 100;
     Left := 8;
     Width := AMsgDialog.ClientWidth - 16;
    end;

    with ATimer do
    begin
     Interval := 1000;
     OnTimer:=DialogTimer;
    end;

    case ShowModal of
     ID_YES: ShowMessage('Answered "Yes".') ;
     ID_NO: ShowMessage('Answered "No".') ;
     ID_CANCEL: ShowMessage('Time up!')
    end;//case
   finally
    ATimer.OnTimer := nil;
    Free;
   end;
end;


procedure TForm1.DialogTimer(Sender: TObject) ;
var
   aPB : TProgressBar;
begin
   if NOT (Sender is TTimer) then Exit;

   if ((Sender as TTimer).Owner) is TForm then
   with ((Sender as TTimer).Owner) as TForm do
   begin
     aPB := TProgressBar(FindComponent('Progress')) ;

     if aPB.Position >= aPB.Max then
       ModalResult := mrCancel
     else
       aPB.StepIt;
   end;
end;
Cevapla