12.06.2015, 16:08
|
Прохожий
|
|
Регистрация: 11.06.2015
Сообщения: 3
Версия Delphi: Embarcadero XE3
Репутация: 10
|
|
Прикольненько получилось.
.
Код:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;
type
TForm1 = class(TForm)
Button1 : TButton;
Button2 : TBitBtn;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure OnTimer(Sender: TObject);
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.dfm}
const
MsgText = #10'ВНИМАНИЕ !!!'#10#10'Есть неотправленная отчетность 364-П !'#10#10'Запустить отправку почты (АСТРА) ?'#10#10'НЕТ - через %d секунд(ы).'#10;
MsgCaption = 'Осталось %d секунд';
BtnCaption = 'ОK (%d сек.)';
MsgBtnCaption1 = 'Да - %d сек.';
MsgBtnCaption2 = 'Нет - %d сек.';
var
MyMsgDialog : TForm;
Sec : Integer;
procedure TForm1.OnTimer(Sender: TObject);
var
Control : TControl;
begin
with MyMsgDialog do
begin
Caption:=Format(MsgCaption, [Sec]);
TButton(FindComponent('Yes')).Caption:=Format(MsgBtnCaption1, [Sec]);
TButton(FindComponent('Cancel')).Caption:=Format(MsgBtnCaption2, [Sec]);
TLabel(FindComponent('Message')).Alignment:=taCenter;
TLabel(FindComponent('Message')).Caption:=Format(MsgText, [Sec]);
end;
Button2.Caption:=Format(BtnCaption, [Sec]);
if (Sec = 0) then
begin
MyMsgDialog.ModalResult:=ID_OK;
Button2.Caption:='ОК'
end;
Dec(Sec);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Timer : TTimer;
Control : TControl;
Btn1X : Integer;
begin
// Создаем диалог
MyMsgDialog:=CreateMessageDialog(MsgText, mtWarning, [mbYes, mbCancel]);
// Создаем таймер
Timer:=TTimer.Create(MyMsgDialog);
Timer.Enabled:=False;
// 10 - это кол-во секунд до закрытия
Sec:=10;
with MyMsgDialog do
begin
try
Caption:='';
Width:=400;
// Height:=300;
Font.Color:=clRed;
// Font.Size:=12;
Control:=FindChildControl('Yes');
if ((Control <> nil) and (Control is TButton)) then
begin
(Control as TButton).Left:=25;
Btn1X:=(Control as TButton).Left;
(Control as TButton).Width:=100;
(Control as TButton).Caption:='Да';
end;
Control:=FindChildControl('Cancel');
if ((Control <> nil) and (Control is TButton)) then
begin
(Control as TButton).Left:=Btn1X + 200;
(Control as TButton).Width:=100;
(Control as TButton).Caption:='Нет';
end;
// Задаем параметры таймера
Timer.Enabled:=True;
Timer.OnTimer:=OnTimer;
OnTimer(Self);
// Показываем окно как модальное
case ShowModal of
ID_OK, ID_YES : begin
Button2.Caption:='ОК - Да';
MyMsgDialog.Close;
end;
ID_CANCEL : begin
Button2.Caption:='ОК - Нет';
end;
end;
finally
// Освобождаем переменные
Timer.Free;
Free;
end;
end;
end;
end.
|