XtraMessageBoxEventArgs.Visible Property
Gets or sets whether the user checked the Do not show this message again checkbox and whether to show the XtraMessageBox again.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
Property Value
Type | Default | Description |
---|---|---|
Boolean | true | true, if the user did not check the checkbox and the XtraMessageBox is shown again; false, if the user checked the checkbox and suppressed the XtraMessageBox. |
Remarks
The XtraMessageBox can display the “Do not show this message again“ checkbox.
If a user checks this checkbox and closes the message, the next XtraMessageBox.Show method call that uses the same XtraMessageBoxArgs object does not show a message.
Display the Checkbox
To display the “Do not show this message again“ checkbox, set the XtraMessageBoxArgs.DoNotShowAgainCheckBoxVisible property to true.
private void Custom_EventHandler(object sender, EventArgs e) {
XtraMessageBoxArgs xma = new XtraMessageBoxArgs();
xma.Caption = "XtraMessageBox";
xma.Text = "This is a message.";
xma.DoNotShowAgainCheckBoxVisible = true;
XtraMessageBox.Show(xma);
}
You can use the XtraMessageBoxArgs.DoNotShowAgainCheckBoxText property to change the checkbox’s text.
private void Custom_EventHandler(object sender, EventArgs e) {
XtraMessageBoxArgs xma = new XtraMessageBoxArgs();
// ...
xma.DoNotShowAgainCheckBoxText = "Custom Text";
XtraMessageBox.Show(xma);
}
The XtraMessageBoxArgs.Load and XtraMessageBoxArgs.Closed events occur when the XtraMessageBox is opened or closed. These events allow you to determine whether a user checked the “Do not show again“ checkbox. Handle these events to read, store, and retrieve the following property values:
Property | Description |
---|---|
XtraMessageBoxEventArgs.Visible |
Gets or sets whether an XtraMessageBox is visible. |
XtraMessageBoxEventArgs.DialogResult | Gets or sets the DialogResult value that corresponds to the button the user chose in an XtraMessageBox. |
You can call the XtraMessageBoxClosedArgs.SaveToRegistry and RestoreFromRegistry() methods to save and load the property values to (from) a registry or store these values in a local variable, a file on local storage, a database, etc.
Process the Visible and DialogResult Property Values
Store in the Registry
Subscribe to the XtraMessageBoxArgs.Load and XtraMessageBoxArgs.Closed events. In the Closed event handler, call the SaveToRegistry() method that saves the XtraMessageBoxEventArgs.Visible
and XtraMessageBoxEventArgs.DialogResult property values to HKEY_CURRENT_USER\Software\RegistryPath\RegistryKey. The RegistryPath and RegistryKey are specified by the XtraMessageBox.RegistryPath and XtraMessageBoxArgs.RegistryKey properties. If you do not set them, the application generates these parameters automatically:
- RegistryKey - a unique ID based on XtraMessageBoxArgs parameters.
- RegistryPath - a result of the Combine(String[]) method call:
Path.Combine(Application.CompanyName, Application.ProductName, "Messages")
To retrieve the Visible and DialogResult property values, call RestoreFromRegistry().
private void Custom_EventHandler(object sender, EventArgs e) {
XtraMessageBoxArgs xma = new XtraMessageBoxArgs();
// ...
xma.RegistryKey = "ThisIsARegistryKey";
xma.RegistryPath = "ThisIsARegistryPath";
xma.Load += Xma_Load;
xma.Closed += Xma_Closed;
XtraMessageBox.Show(xma);
}
private void Xma_Load(object sender, XtraMessageBoxLoadArgs e) {
e.RestoreFromRegistry();
if(e.DialogResult == DialogResult.OK) {
// Apply custom settings.
}
else if(e.DialogResult == DialogResult.Cancel) {
// Apply custom settings.
}
}
private void Xma_Closed(object sender, XtraMessageBoxClosedArgs e) {
e.SaveToRegistry();
if(e.DialogResult == DialogResult.OK) {
// Apply custom settings.
}
else if(e.DialogResult == DialogResult.Cancel) {
// Apply custom settings.
}
}
Store in an External Source
In this example the XtraMessageBoxEventArgs.Visible
and XtraMessageBoxEventArgs.DialogResult property values are stored in a text file on the local storage.
private void Form1_DoubleClick(object sender, EventArgs e) {
XtraMessageBoxArgs xma = new XtraMessageBoxArgs();
// ...
xma.Load += Xma_Load;
xma.Closed += Xma_Closed;
XtraMessageBox.Show(xma);
}
private void Xma_Load(object sender, XtraMessageBoxLoadArgs e) {
string messageDisplayed = System.IO.File.ReadAllText(@"C:\Users\Public\Documents\Settings.txt");
string dialogResult = System.IO.File.ReadAllText(@"C:\Users\Public\Documents\DialogResult.txt");
if(Convert.ToBoolean(messageDisplayed) == true) {
e.Visible = true;
}
if(button == DialogResult.OK) {
// Apply custom settings.
}
else if(button == DialogResult.Cancel) {
// Apply custom settings.
}
}
private void Xma_Closed(object sender, XtraMessageBoxClosedArgs e) {
bool messageDisplayed = e.Visible;
DialogResult dialogResult = e.DialogResult;
System.IO.File.WriteAllText(@"C:\Users\Public\Documents\Settings.txt", messageDisplayed.ToString());
System.IO.File.WriteAllText(@"C:\Users\Public\Documents\DialogResult.txt", dialogResult.ToString());
if(e.DialogResult == DialogResult.OK) {
// Apply custom settings.
}
else if(e.DialogResult == DialogResult.Cancel) {
// Apply custom settings.
}
}
Display the Message After the User Suppressed It
If you need to show an XtraMessageBox a user suppressed, call the ShowMessage(Boolean) method in the XtraMessageBoxArgs.Load event handler. The XtraMessageBox opens with the checkbox unchecked. If you need to forcibly show an XtraMessageBox with the checkbox checked, pass true to the ShowMessage() method.
private void Xma_Load(object sender, XtraMessageBoxLoadArgs e) {
e.RestoreFromRegistry();
if(e.Visible == false /* && SecondCondition*/ ) {
e.ShowMessage();
}