-
Create two alert buttons .
You’ll be creating two alert buttons in the form’s Load event. You can create the event handler for the Load event by double-clicking the form’s header in Design View. Once the buttons are instantiated with a few properties set, you’ll need to add them to the AlertButtons collection and then create the event handler for the AlertButtonClicked event. Place the following code in the form’s Load event.
Note
|
Note
You’ll need to place the Snooze and Dismiss images in your project’s startup path. Right-click each image, select Save Target As…, and then navigate to your project’s startup path and click Save.
|
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim snoozeButton As UltraDesktopAlertButton = New UltraDesktopAlertButton()
Dim dismissButton As UltraDesktopAlertButton = New UltraDesktopAlertButton()
snoozeButton.Key = "SnoozeButton"
dismissButton.Key = "DismissButton"
snoozeButton.Appearance.Image = _
New Bitmap(Application.StartupPath + "\Snooze.gif")
dismissButton.Appearance.Image = _
New Bitmap(Application.StartupPath + "\Dismiss.gif")
Me.UltraDesktopAlert1.AlertButtons.AddRange(New UltraDesktopAlertButton() _
{snoozeButton, dismissButton})
AddHandler UltraDesktopAlert1.AlertButtonClicked, _
AddressOf UltraDesktopAlert1_AlertButtonClicked
End Sub
private void Form1_Load(object sender, EventArgs e)
{
UltraDesktopAlertButton snoozeButton = new UltraDesktopAlertButton();
UltraDesktopAlertButton dismissButton = new UltraDesktopAlertButton();
snoozeButton.Key = "SnoozeButton";
dismissButton.Key = "DismissButton";
snoozeButton.Appearance.Image =
new Bitmap(Application.StartupPath + @"..\Snooze.gif");
dismissButton.Appearance.Image =
new Bitmap(Application.StartupPath + @"..\Dismiss.gif");
this.ultraDesktopAlert1.AlertButtons.AddRange(new UltraDesktopAlertButton[]
{ snoozeButton, dismissButton });
this.ultraDesktopAlert1.AlertButtonClicked +=
new AlertButtonClickedHandler(this.ultraDesktopAlert1_AlertButtonClicked);
}
-
Handle the Click event for the Alert buttons .
The two alert buttons are going to snooze and dismiss the Reminder dialog box respectively. Therefore, you need to create the AlertButtonClicked event and add code to perform these two tasks. You’ll start off by getting a reference to the Appointment object through the EventArgs. Once you have the reference, you can use a switch/select statement to handle the different button’s click events.
Private Sub UltraDesktopAlert1_AlertButtonClicked _
(ByVal sender As System.Object, ByVal e As AlertButtonClickedEventArgs) _
Handles UltraDesktopAlert1.AlertButtonClicked
Dim alertButtonAppt As Appointment = e.WindowInfo.Data
Select Case e.Button.Key
Case "SnoozeButton"
alertButtonAppt.Reminder.Snooze( _
SnoozeIntervalUnits.Minutes, 15)
MessageBox.Show( _
"You will be reminded again in 15 minutes.")
Case "DismissButton"
alertButtonAppt.Reminder.Enabled = False
MessageBox.Show("You will not be reminded about " + _
alertButtonAppt.Subject + " again.")
End Select
End Sub
private void ultraDesktopAlert1_AlertButtonClicked(object sender,
AlertButtonClickedEventArgs e)
{
Appointment alertButtonAppt = e.WindowInfo.Data as Appointment;
switch (e.Button.Key)
{
case "SnoozeButton":
alertButtonAppt.Reminder.Snooze(
SnoozeIntervalUnits.Minutes, 15);
MessageBox.Show(
"You will be reminded again in 15 minutes.");
break;
case "DismissButton":
alertButtonAppt.Reminder.Enabled = false;
MessageBox.Show("You will not be reminded about " +
alertButtonAppt.Subject + " again.");
break;
}
}
When you run the application and click the Create Appointment button, you will notice an addition to the desktop alert reminder. You will see two buttons at the lower-left corner of the desktop alert window. Clicking the first button will snooze the reminder and display a dialog box confirming that the reminder was snoozed. Clicking the second button will dismiss the reminder and display a dialog box confirming that the reminder was dismissed. The next task is Adding a Menu to the Desktop Alert Reminder’s Drop-Down Button.