Back to Devexpress

Message Dialog Boxes

vcl-405251-expresscrossplatformlibrary-common-features-message-dialog-boxes.md

latest10.8 KB
Original Source

Message Dialog Boxes

  • Dec 30, 2025
  • 5 minutes to read

A message box is a modal dialog designed to display important information and optionally allow a user to make a choice or confirm an operation. All DevExpress products use the TdxMessageDialogForm class to display message dialog boxes that support skins and BBCode-inspired markup tags:

Create a Skinnable Message Box

Skinnable message dialog boxes allow you to keep the appearance of your application consistent. They import all look & feel settings from the TdxSkinController component if it is in an application project. To create such a message box, call one of the global DevExpress methods that have the same API as the corresponding standard VCL library methods:

DevExpress MethodStandard VCL MethodDescription
dxCreateMessageDialogCreateMessageDialogCreates a message dialog box with a specified dialog type and message. Allows you to specify a set of buttons and move focus to one of the buttons.
dxMessageBoxTApplication.MessageBoxOpens a message dialog box that displays a specified message, title, and buttons (configured using a combination of flags). Allows you to associate the message box with an owner window.
dxMessageDlgMessageDlgOpens a message dialog box with a specified dialog type, message, and a set of buttons.
dxMessageDlgPosMessageDlgPosOpens a message dialog box at a specified position on the screen. Allows you to specify the default button.
dxMessageDlgPosHelpMessageDlgPosHelpOpens a message dialog box associated with a help topic and positions the dialog box at specific screen coordinates.
dxShowMessageShowMessageOpens a generic message dialog box with an OK button.
dxShowMessageFmtShowMessageFmtOpens a generic message dialog box with a formatted message and an OK button.
dxShowMessagePosShowMessagePosOpens a generic message dialog box at a specified position on the screen.

All DevExpress controls and components invoke these global methods to display message boxes. If you call DevExpress methods to invoke message boxes, you can use the global dxUseStandardMessageDialogs global variable to switch between standard and skinnable DevExpress message boxes.

Message Box Content Formatting

All message box creation methods allow you to pass the required message as a parameter. Once a message dialog box form is created, you can use its Message property to change the displayed message.

Captions in multiple DevExpress controls can use Bulletin Board Code (BBCode) markup tags. These tags allow you to define hyperlinks and apply formatting attributes – bold, italic, superscript, underline, etc.

You can apply multiple formatting attributes to the same text range in any combination:

[URL=https://www.devexpress.com][B]Dev[/B][COLOR=orange]Express[/COLOR][/URL]

Refer to the following topic for detailed information on all available formatting options: BBCode-Inspired Text Formatting Markup.

Customize Dialog Buttons

The TdxMessageDialogForm includes one or more TcxButton components to display message box buttons. You can use the TdxMessageDialogForm.Buttons property or call the TdxMessageDialogForm.FindButton function to change predefined button captions before the form is displayed. The following code example changes captions of Yes , No , and Cancel buttons:

delphi
uses dxMessageDialog;
// ...
var
  ADialog: TdxMessageDialogForm;
  AMessage: string;
begin
  AMessage := 'One or more margins are set outside the printable area of the page.' + #13#10 +
    #13#10 + 'Click the [B]Fix[/B] button to increase these margins.';
  ADialog := dxCreateMessageDialog(AMessage, mtWarning, mbYesNoCancel);
  try
    ADialog.FindButton(mbYes).Caption := 'Fix';
    ADialog.FindButton(mbNo).Caption := 'Restore Original';
    ADialog.FindButton(mbCancel).Caption := 'Close';

    ADialog.AlignButtons; // Recalculates the button layout
    ADialog.ShowModal; // Invokes the form as a modal dialog
  finally
    ADialog.Free; // Releases the message box when a user closes it
  end;
end;
cpp
#include "dxMessageDialog.hpp"
// ...
  TdxMessageDialogForm *ADialog;
  UnicodeString AMessage = "One or more margins are set outside the printable area of the page.\n" +
    "\n" + "Click the [B]Fix[/B] button to increase these margins.";
  ADialog = dxCreateMessageDialog(AMessage, wtWarning, mbYesNoCancel);
  try
  {
    ADialog->FindButton(mbYes)->Caption = "Fix";
    ADialog->FindButton(mbNo)->Caption = "Restore Original";
    ADialog->FindButton(mbCancel)->Caption = "Close";

    ADialog->AlignButtons(); // Recalculates the button layout
    ADialog->ShowModal(); // Invokes the form as a modal dialog
  }
  __finally
  {
    delete ADialog; // Releases the message box when a user closes it
  }

Customize the Message Box Layout

The message dialog box form has multiple layout customization options:

Change the UseLatestCommonDialogs Global Variable

Set the UseLatestCommonDialogs global variable to True or False to switch between two predefined layouts also available for standard VCL message boxes:

ValueDescriptionExample
True (Default)The modern message box style available in Microsoft Windows® Vista and newer operating systems. The message box has a fixed width; buttons are right-aligned.
FalseThe message box style found in Microsoft Windows® XP and older operating systems. The width of the message box depends on its content size; buttons are centered.

Use the TdxMessageDialogForm.Style Property

You can set the form’s Style property to mdsMessageBox or mdsMessageDlg to switch between two layout styles that imitate message boxes that different VCL library methods can invoke:

ValueDescriptionExample
mdsMessageDlg (default)This message dialog style imitates dialogs that the standard MessageDlg function invokes. The message box layout has increased paddings between borders and the message icon.
mdsMessageBoxThis message box style imitates dialog boxes that the standard MessageBox function invokes. The message box layout is smaller compared to the message dialog style (mdsMessageDlg).

Limitation

This layout customization option is available only before you manually display a skinnable message dialog box form after you call the dxCreateMessageDialog function or the form constructor.

Create a Custom Message Dialog Box Form

You can replace the built-in message dialog box form with a custom implementation:

  1. Derive a custom form from the TdxMessageDialogForm class.
  2. Assign a reference to your form class to the dxMessageDialogFormClass global variable.

See Also

Common Features