Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to: Send a Notification

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

You can use a Notification whenever a user should take action in your application, such as prompting to send data. Typically, you send a notification when an event occurs or a condition is met, but, for simplicity, this example displays a notification when a button is clicked. You can process responses to notifications by providing code to handle the ResponseSubmitted event.

The message in a notification can be plain text or HTML. HTML enables you to send a small HTML form that contains check boxes, buttons, lists, and other HTML elements. This example uses a simple form with Submit and Cancel buttons.

The Cancel button is identified by "cmd:2", which Windows CE uses to dismiss notifications. If cmd:2 is the name of an HTML button or other element in a message balloon, the ResponseSubmitted event is not raised. The notification is dismissed, but its icon is placed on the title bar and can be responded to at a later time.

To send a notification

  1. Create a Pocket PC Windows application.

  2. Add a Notification and a Button to the form.

  3. Create a Notification instance.

    
                this.notification1 = new Microsoft.WindowsCE.Forms.Notification();
    
    
  4. Add the following code to handle the Click event of the button.

    
    private void button1_Click(object sender, System.EventArgs e)
    {
    
        StringBuilder HTMLString = new 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>");
    
        //Set the Text property to the HTML string.
        notification1.Text = HTMLString.ToString();
    
        FileStream IconStream = new FileStream(".\\My Documents\\notify.ico",
            FileMode.Open, FileAccess.Read);
        notification1.Icon = new Icon(IconStream, 16, 16);
        notification1.Caption="Notification Demo";
        notification1.Critical = false;
    
        // Display icon up to 10 seconds.
        notification1.InitialDuration = 10;
        notification1.Visible = true;
    }
    
    
    
  5. Add the following code to handle the ResponseSubmitted event.

    
    // When a ResponseSubmitted event occurs, this event handler
    // parses the response to determine values in the HTML form.
    notification1.ResponseSubmitted += 
        delegate (object obj, ResponseSubmittedEventArgs resevent)
        {
            if (resevent.Response.Substring(0,6) == "notify")
            {
                // Add code here to respond to the notification.
            }
        };
    
    
    

This example requires references to the following namespaces:

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.