Back to Devexpress

How to: Respond to Clicks on Alert Windows

windowsforms-5757-controls-and-libraries-messages-notifications-and-dialogs-alert-windows-how-to-respond-to-clicking-on-alert-windows.md

latest2.3 KB
Original Source

How to: Respond to Clicks on Alert Windows

  • Mar 02, 2022
  • 2 minutes to read

The following example shows how you can respond to an end-user clicking an alert window’s text. To respond to these actions, the AlertControl.AlertClick event is handled.

In the example, it’s assumed that alert windows are used to show notifications to end-users when a new e-mail arrives. When a new alert window is created, a custom MailData object is associated with the window. This object contains information on the e-mail received, and it is accessed and processed while handling the AlertControl.AlertClick event.

csharp
private void ShowAlertWindow() {
    Form owner;
    string caption, text, hotTrackedText;
    Image image;
    MailData mailData;
    // Initialize the owner, caption, text, hotTrackedText, image and mailData
    // ...
    // Show an alert window with these parameters
    alertControl1.Show(owner, caption, text, hotTrackedText, image, mailData);
}

private void alertControl1_AlertClick(object sender, AlertClickEventArgs e) {
    // Get and process the data associated with the current alert window.
    MailData mailData = e.Info.Tag as MailData;
    ShowEmail(mailData);
}

private void ShowEmail(MailData mailData) {
    //...
}

public class MailData {
    //...
}
vb
Private Sub ShowAlertWindow()
    Dim owner As Form
    Dim caption, text, hotTrackedText As String
    Dim image As Image
    Dim mailData As MailData
    ' Initialize the owner, caption, text, hotTrackedText, image and mailData
    ' ...
    ' Show an alert window with these parameters
    alertControl1.Show(owner, caption, text, hotTrackedText, image, mailData)
End Sub

Private Sub AlertControl1_AlertClick(ByVal sender As System.Object, _
ByVal e As AlertClickEventArgs) Handles AlertControl1.AlertClick
    ' Get and process the data associated with the current alert window.
    Dim mailData As MailData = TryCast(e.Info.Tag, MailData)
    ShowEmail(mailData)
End Sub

Private Sub ShowEmail(ByVal mailData As MailData)
    '...
End Sub

Public Class MailData
    '...
End Class