Teşekkürler güzel bir örnek. Bunu fonksiyon haline getirelim genel kullanım için kolaylık sağlasın...
Kod: Tümünü seç
Function MyMessageChkBoxDlg( DlgTitle, DlgMsg:String; DlgType: TMsgDlgType; Buttons:TMsgDlgButtons; ChkMsg:String ):Word;
var
AMsgDialog : TForm;
ACheckBox : TCheckBox;
begin
Result := 0;
AMsgDialog := CreateMessageDialog( DlgMsg, DlgType, Buttons) ;
ACheckBox := TCheckBox.Create(AMsgDialog) ;
with AMsgDialog do
try
Caption := DlgTitle;
Height := Height + 20;
with ACheckBox do
begin
Parent := AMsgDialog;
Caption := ChkMsg;
Top := AMsgDialog.Height - ACheckBox.Height - 40;
Left := 8;
Width := Canvas.TextWidth( Caption ) + 20;
end;
ShowModal;
if ACheckBox.Checked then Result := 100
finally
Inc(Result, AMsgDialog.ModalResult);
Free;
end;
end;
- CheckBox için, üretilen mesaj penceresinin mevcut yüksekliğine
+20 height eklemek kafi. (
CheckBox Font büyüklüğüne göre Canvas.TextHeight ile daha da dinamik hale getirilebilir siz bilirsiniz )
- Nihayetinde;
CheckBox işaretli ise sonuca temsili olarak
100 sayısını ekledik. Dönen sonucun 100'den büyük olup olmadığını kontrol ederek hem işaretli olup olmadığını, hem de varsa bu rakamı düşerek gerçek sonucu elde etmiş olduk.
Kullanımı ise şöyle olacak...
Kod: Tümünü seç
procedure TForm1.Button1Click(Sender: TObject);
Var
Cevap : Word;
Sonuc : String;
begin
Sonuc := 'CheckBox ONAYLANMAMIŞ';
Cevap := MyMessageChkBoxDlg( 'Başlık', 'Test Mesajı'#13'1'#13'2'#13'3'#13'4'#13'5', mtConfirmation, [mbYes, mbNo, mbCancel], 'Bir Daha Gösterme');
If Cevap > 100 then begin
Dec(Cevap, 100);
Sonuc := 'CheckBox Onaylanmış';
end;
If Cevap = mrYes then Sonuc := 'Yes - '+ Sonuc
else If Cevap = mrNo then Sonuc := 'No - '+ Sonuc
else if Cevap = mrCancel then Sonuc := 'Cancel - '+ Sonuc;
ShowMessage( Sonuc);
end;