delphidelphi-2006

Change caption and attributes of ShowMessage dialog


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?


Solution

  • 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.