Search code examples
delphivcldelphi-xe7vcl-styles

Exclude VCL Styles from styling Dialog / ShowMessage borders


Is there any way to exclude VCL Styles from styling a system dialogs' border.

Sepecifically a dialog that is shown by calling MessageDlg or ShowMessage.

I read some articles on "The Road To Delphi" (which is an excellent site btw) but couldn't find the answer.

Here is what i want to achieve:

Now (Carbon Style with styled borders):

now

Goal (Carbon Style with standard windows borders):

enter image description here

I still want to have styled controls but no styled border.

Removing seBorder from the parent forms StyleElements doesn't do the trick.

enter image description here

Thanks!


Solution

  • MessageDlg() and ShowMessage() are Delphi VCL functions. They dynamically create a Delphi TForm and display that, so you do not have a chance to customise it. However, you can use CreateMessageDialog() instead to create the same TForm, then modify its style elements as needed, and then show it. For instance:

    function DoMessageDlgPosHelp(MessageDialog: TForm; X, Y: Integer): Integer;
    begin
      with MessageDialog do
        try
          if X >= 0 then Left := X;
          if Y >= 0 then Top := Y;
          if (Y < 0) and (X < 0) then Position := poScreenCenter;
          Result := ShowModal;
        finally
          Free;
        end;
    end;
    
    procedure ShowStyledMessage(const Msg: string; const StyleElements: TStyleElements);
    var
      Form: TForm;
    begin
      Form := CreateMessageDialog(Msg, mtCustom, [mbOK]);
      Form.StyleElements := StyleElements;
      DoMessageDlgPosHelp(Form, -1, -1);
    end;
    

    Call it like this:

    ShowStyledMessage('Some text', [seFont, seClient]);
    

    And the dialog looks like this:

    screenshot