How To: Showing Notifications with Mobile 5
Question: My company is in the process of developing an Windows Mobile 5 mobile application. One of the things that we need to do for the application design is show notification. I have read that this can be done. However, I can’t seem to figure out how it can be done. Do you have any code samples or ideas about how this can be done?
Answer: When developing mobile applications using Windows Mobile 5 this is definitely an extremely useful feature to include within your application. The Microsoft.WindowsCE.Forms namespace provides a managed implementation of the notifications function. It is important to remember that this is only supported on the Pocket PC platform.
To create a sample program to demonstrate this. First create a Device application that targets the Windows Mobile 5 platform. If you are unfamiliar with how to do this you can follow the steps outlined here. Once you have created the application place a notification control and three buttons on the form as shown below.
Also you can download this sample application from here.
Sample Notification:
Within the form place the following code behind the “Full Notification” button on the form and enter the following code behind the button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With Notification1
.Caption = "Welcome to Mobile 5"
.InitialDuration = 200
.Text = "This is the notification text"
.Visible = True
End With
End Sub
Once the application is run and the button is pressed you can see the notification as shown below;
Hidden Notification
Within the form place the following code behind the “Not Visible” button the form and enter the following code behind the button
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
With Notification1
.Caption = "Welcome to Mobile 5"
.Text = "This is the notification text"
.Visible = True
.InitialDuration = 0
End With
End Sub
Once the application is run and the button is pressed you can see the notification as shown below;
HTML Notification
For more advanced scenarios the notifications can also use HTML. The HTML content is rendered in the message balloon and you can respond to values in the an HTML form by parsing the response string. Within the form place the following code behind the “HTML Notification” button.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim HTMLString As New System.Text.StringBuilder
HTMLString.Append("<html><body>")
HTMLString.Append("Submit data?")
HTMLString.Append("<form method=\'GET\' action=notify>")
HTMLString.Append("<input type='submit'>")
HTMLString.Append( _
"<input type=button name='cmd:2' value='Cancel'>")
HTMLString.Append("</body></html>")
With Notification1
.Caption = "Welcome to Mobile 5"
.InitialDuration = 200
.Text = HTMLString.ToString()
.Visible = True
End With
End Sub
Once the application is run and the button is pressed you can see the notifications as shown below.
Comments
- Anonymous
February 13, 2006
Question: My company is in the process of developing an Windows Mobile 5 mobile application. One of the...