Message Dialog Boxes
- 4 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 the specified settings. |
dxMessageBox | TApplication.MessageBox | Invokes a modal message box dialog. |
dxMessageDlg | MessageDlg | Invokes a modal message box dialog. |
dxMessageDlgPos | MessageDlgPos | Invokes a modal message box dialog at the specified position on the screen. |
dxMessageDlgPosHelp | MessageDlgPosHelp | Invokes a message box dialog 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 call these global methods to display message boxes. If you use DevExpress methods to invoke message boxes, you can use the global dxUseStandardMessageDialogs global variable to switch between standard and skinnable message boxes.
Customize Dialog Buttons
The TdxMessageDialogForm uses the TcxButton components to display message box buttons. You can use the TdxMessageDialogForm.Buttons property or the TdxMessageDialogForm.FindButton function to change predefined button captions before the form is displayed. The following code example changes captions of the Yes, No, and Cancel buttons:
var
ADialog: TdxMessageDialogForm;
AMessage: string;
begin
AMessage := 'One or more margins are set outside the printable area of the page.' + #13#10 +
'Choose the [B]Fix[/B] button to increase the appropriate 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;
end;
Customize the Message Box Layout
The message dialog box form has multiple layout customization options:
Change the UseLatestCommonDialogs Global Variable
Set this variable to False or True to switch between two predefined layouts also available for standard message boxes:
Value | Description | Example |
---|---|---|
True (Default) | The modern message box style available on Microsoft Windows® Vista and later operating systems. The message box has a fixed width; the 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; the buttons are centered. |
Use the TdxMessageDialogForm.Style Property
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.
Set the form’s Style property to mdsMessageBox or mdsMessageDlg to switch between two layout styles that imitate the message boxes that different VCL library methods can invoke:
Value | Description | Example |
---|---|---|
mdsMessageDlg (default) | This message dialog style imitates the 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 the dialog boxes that the standard MessageBox function invokes. The message box layout is smaller compared to the message dialog style (mdsMessageDlg). |
Create a Custom Message Dialog Box Form
You can replace the 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.