Display progress bar in message window

Source: Internet
Author: User

 

Dynamically create a message window and display a progress bar in the window. Select a button within the progress bar.

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, extctrls, stdctrls, comctrls;

Type
Tform1 = Class (tform)
Button1: tbutton;
Procedure button1click (Sender: tobject );
Procedure dialogtimer (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

{$ R *. DFM}

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: = 95;
Left: = 8;
Width: = amsgdialog. clientwidth-16;
End;

With atimer do
Begin
Interval: = 1000;
Ontimer: = dialogtimer;
End;

Case showmodal
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: = mrno
Else
APB. stepit;
End;
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.