--> Custom Message Dialog Dephi | Delphi Tips Trick

For Newbie

Tuesday 15 November 2011

Custom Message Dialog Dephi

| Tuesday 15 November 2011

Change the default display message dialog with a custom font name, styles and color, background color and the button text and button cursor. Able to display the Message Dialog in english or another language.
Function declaration:MyMsgDlg function (const Message: string; TipeDlg: TMsgDlgType; Buttons: TMsgDlgButtons;
  
Captions: array of string; Title: String; mFont: TFont; buttonKursor: TCursor;
  
BGCOLOR: TColor): Integer;var
  
xMsgDlg: TForm;
  
i: Integer;
  
dlgButton: TButton;
  
CaptionIndex: Integer;begin
  
xMsgDlg: = CreateMessageDialog (Message, TipeDlg, Buttons);
  
if BGCOLOR <> -1 then xMsgDlg.Color: = bgcolor;
  
captionIndex: = 0;
  
xMsgDlg.Caption: = Title;
  
if mFont <> nil then xMsgDlg.Font: = mFont
  
else xMsgDlg.Font.Handle: = 0;
  
for i: = 0 to xMsgDlg.ComponentCount - 1 do
  
begin
    
if (xMsgDlg.Components [i] is TButton) then
    
begin
      
dlgButton: = TButton (xMsgDlg.Components [i]);
      
dlgButton.Cursor: = buttonKursor;
      
if CaptionIndex> High (Captions) then Break;
      
dlgButton.Caption: = Captions [CaptionIndex];
      
Inc. (CaptionIndex);
    
end;
  
end;
  
Result: = xMsgDlg.ShowModal;end;
Example of implementation:var
  
/ / Custom Fonts
  
myDlgFont: TFont;TForm1.FormCreate procedure (Sender: TObject);begin
  
{Font for MyMsgDlg be public, so no need to
  
again when calling a function declared MyMsgDlg ..
  
Unless you want it different font style}
  
myDlgFont: = TFont.Create;
  
with myDlgFont do
  
begin
    
Name: = 'Comic Sans MS';
    
Size: = 8;
    
Color: = clMaroon;
    
{If you want to bold + italic font style
    
style: = [fsBold, fsItalic];}
  
end;end;
TForm1.FormDestroy procedure (Sender: TObject);begin
  
/ / Free Custom Fonts
  
myDlgFont.Free;end;
procedure TForm1.Button1Click (Sender: TObject);var
  
rDlg: Integer;begin
  
rDlg: = MyMsgDlg ('Proceed to Next Process?', mtConfirmation,
         
[MbYes, mbNo, mbCancel], ['Yes', 'No', 'Cancel'], 'Confirmation',
         
myDlgFont, crHandPoint, $ 00F0F0F0);
  
rDlg case of
  
/ / If the user clicks on Yes
  
ID_YES: ShowMessage ('You Clicking YES');
  
/ / If the user clicks No
  
ID_NO: ShowMessage ('You Clicking NO');
  
/ / If the user clicks Cancel
  
ID_CANCEL: ShowMessage ('You Clicking CANCEL');
  
end;end;
/ / To display the Standardprocedure TForm1.Button2Click (Sender: TObject);begin
  
MyMsgDlg ('Proceed to Next Process?', MtConfirmation,
  
[MbYes, mbNo, mbCancel], ['Yes', 'No', 'Cancel'], 'Confirmation',
  
nil, crDefault, -1);end;

Related Posts

No comments: