Back to Devexpress

XtraMessageBoxArgs.DoNotShowAgainCheckBoxVisible Property

windowsforms-devexpress-dot-xtraeditors-dot-xtramessageboxargs-032880ef.md

latest12.4 KB
Original Source

XtraMessageBoxArgs.DoNotShowAgainCheckBoxVisible Property

Gets or sets whether the “Do not show this message again“ checkbox is shown in an XtraMessageBox.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public bool DoNotShowAgainCheckBoxVisible { get; set; }
vb
Public Property DoNotShowAgainCheckBoxVisible As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true if the “Do not show this message again“ checkbox is shown in an XtraMessageBox ; otherwise, false.

|

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.

csharp
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);
}
vb
Private Sub Custom_EventHandler(ByVal sender As Object, ByVal e As EventArgs)
    Dim xma As New XtraMessageBoxArgs()
    xma.Caption = "XtraMessageBox"
    xma.Text = "This is a message."
    xma.DoNotShowAgainCheckBoxVisible = True
    XtraMessageBox.Show(xma)
End Sub

You can use the XtraMessageBoxArgs.DoNotShowAgainCheckBoxText property to change the checkbox’s text.

csharp
private void Custom_EventHandler(object sender, EventArgs e) {
    XtraMessageBoxArgs xma = new XtraMessageBoxArgs();
    // ...
    xma.DoNotShowAgainCheckBoxText = "Custom Text";
    XtraMessageBox.Show(xma);
}
vb
Private Sub Custom_EventHandler(ByVal sender As Object, ByVal e As EventArgs)
    Dim xma As New XtraMessageBoxArgs()
    ' ...
    xma.DoNotShowAgainCheckBoxText = "Custom Text"
    XtraMessageBox.Show(xma)
End Sub

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:

PropertyDescription
XtraMessageBoxEventArgs.VisibleGets or sets whether an XtraMessageBox is visible.
XtraMessageBoxEventArgs.DialogResultGets 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().

csharp
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.
    }
}
vb
Private Sub Custom_EventHandler(ByVal sender As Object, ByVal e As EventArgs)
    Dim xma As New XtraMessageBoxArgs()
    ' ...
    xma.RegistryKey = "ThisIsARegistryKey"
    xma.RegistryPath = "ThisIsARegistryPath"
    AddHandler xma.Load, AddressOf Xma_Load
    AddHandler xma.Closed, AddressOf Xma_Closed
    XtraMessageBox.Show(xma)
End Sub
Private Sub Xma_Load(ByVal sender As Object, ByVal e As XtraMessageBoxLoadArgs)
    e.RestoreFromRegistry()
    If e.DialogResult = DialogResult.OK Then
        ' Apply custom settings.
    ElseIf e.DialogResult = DialogResult.Cancel Then
        ' Apply custom settings.
    End If
End Sub
Private Sub Xma_Closed(ByVal sender As Object, ByVal e As XtraMessageBoxClosedArgs)
    e.SaveToRegistry()
    If e.DialogResult = DialogResult.OK Then
        ' Apply custom settings.
    ElseIf e.DialogResult = DialogResult.Cancel Then
        ' Apply custom settings.
    End If
End Sub

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.

csharp
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.
    }
}
vb
Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As EventArgs)
    Dim xma As New XtraMessageBoxArgs()
    ' ...
    AddHandler xma.Load, AddressOf Xma_Load
    AddHandler xma.Closed, AddressOf Xma_Closed
    XtraMessageBox.Show(xma)
End Sub
Private Sub Xma_Load(ByVal sender As Object, ByVal e As XtraMessageBoxLoadArgs)
    Dim messageDisplayed As String = System.IO.File.ReadAllText("C:\Users\Public\Documents\Settings.txt")
    Dim dialogResult As String = System.IO.File.ReadAllText("C:\Users\Public\Documents\DialogResult.txt")
    If Convert.ToBoolean(messageDisplayed) = True Then
        e.Visible = True
    End If
    If button = DialogResult.OK Then
        ' Apply custom settings.
    ElseIf button = DialogResult.Cancel Then
        ' Apply custom settings.
    End If
End Sub
Private Sub Xma_Closed(ByVal sender As Object, ByVal e As XtraMessageBoxClosedArgs)
    Dim messageDisplayed As Boolean = e.Visible
    Dim dialogResult As 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 Then
        ' Apply custom settings.
    ElseIf e.DialogResult = DialogResult.Cancel Then
        ' Apply custom settings.
    End If
End Sub

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.

csharp
private void Xma_Load(object sender, XtraMessageBoxLoadArgs e) {
e.RestoreFromRegistry();
if(e.Visible == false /* && SecondCondition*/ ) {
    e.ShowMessage();
}
vb
Private Sub Xma_Load(ByVal sender As Object, ByVal e As XtraMessageBoxLoadArgs)
e.RestoreFromRegistry()
If e.Visible = False 'AndAlso SecondCondition 
    Then
    e.ShowMessage()
End If

See Also

XtraMessageBoxArgs Class

XtraMessageBoxArgs Members

DevExpress.XtraEditors Namespace