Change caption and attributes of ShowMessage dialog

Shirish11 picture Shirish11 · Oct 13, 2011 · Viewed 19.9k times · Source

In Delphi can you change the caption of the ShowMessage dialog because by default it is taking my exe name.

And can I change the background color, size of the same?

Answer

zz1433 picture zz1433 · Oct 13, 2011

You can create your own custom dialogs by using delphi's CreateMessageDialog function.

Example below:

var
  Dlg: TForm;
begin
  Dlg := CreateMessageDialog('message', mtInformation, [mbOk], mbOK);
  // Treat Dlg like any other form

  Dlg.Caption := 'Hello World';

  try
    // The message label is named 'message'
    with TLabel(Dlg.FindComponent('message')) do
    begin
      Font.Style := [fsUnderline];

      // extraordinary code goes here
    end;

    // The icon is named... icon
    with TPicture(Dlg.FindComponent('icon')) do
    begin
      // more amazing code regarding the icon
    end;

    Dlg.ShowModal;
  finally
    Dlg.Free;
  end;

and of course you can insert other components aswell into that form dynamically.