Message Dialog Boxes
- 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 Method | Standard VCL Method | Description |
---|---|---|
dxCreateMessageDialog | CreateMessageDialog | Creates a message dialog box form with specified settings. |
dxMessageBox | TApplication.MessageBox | Creates a message dialog box form with the specified settings. |
dxMessageDlg | MessageDlg | Invokes a modal message dialog box. |
dxMessageDlgPos | MessageDlgPos | Invokes a modal message dialog box at the specified position on the screen. |
dxMessageDlgPosHelp | MessageDlgPosHelp | Invokes a message dialog box whose help topic is supplied in a specified help file. |
dxShowMessage | ShowMessage | Invokes a generic message dialog box with an OK button. |
dxShowMessageFmt | ShowMessageFmt | Displays a message dialog box with a formatted message. |
dxShowMessagePos | ShowMessagePos | Invokes the message dialog box at the 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:
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;
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:
Value | Description | Example |
---|---|---|
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. | |
False |
The 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:
Value | Description | Example |
---|---|---|
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. | |
mdsMessageBox |
This 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:
- Derive a custom form from the TdxMessageDialogForm class.
- Assign a reference to your form class to the dxMessageDialogFormClass global variable.