SO WIRD'S GEMACHT: Senden einer Benachrichtigung

Dieser Dokumentation für die Vorschau nur ist und in späteren Versionen geändert. Leere Themen wurden als Platzhalter eingefügt.]

Sie können ein Notification verwenden, wenn ein Benutzer Aktion in Ihrer Anwendung z. B. zum Senden von Daten aufgefordert werden soll. In der Regel wird eine Benachrichtigungen gesendet, wenn ein Ereignis eintritt oder eine Bedingung erfüllt, aber der Einfachheit halber dieses Beispiel zeigt eine Benachrichtigung, wenn eine Schaltfläche geklickt wird. Sie können Antworten auf Benachrichtigungen verarbeiten, indem Sie Code für die Ereignisbehandlung ResponseSubmitted bereitstellen.

Die Nachricht eine Benachrichtigung kann Text oder HTML sein. HTML können Sie ein kleines HTML-Formular senden, das Kontrollkästchen, Schaltflächen, Listen und andere HTML-Elemente enthält. In diesem Beispiel wird ein einfaches Formular mit senden und Abbrechen Schaltflächen.

Abbrechen wird durch "cmd: 2" identifiziert, die Windows CE, verwendet um Benachrichtigungen zu schließen. Wenn cmd:2 der Name einer HTML-Schaltfläche oder eines anderen Elements in einer Sprechblase ist, wird das ResponseSubmitted-Ereignis nicht ausgelöst. Die Benachrichtigung wird geschlossen, aber das Symbol wird auf der Titelleiste platziert und kann zu einem späteren Zeitpunkt beantwortet werden.

Zum Senden einer Benachrichtigung

  1. Erstellen Sie eine Pocket PC-Windows-Anwendung.

  2. Fügen Sie ein Notification und ein Button zum Formular hinzu.

  3. Erstellen Sie eine Instanz Notification.

                                Me.Notification1 = New Microsoft.WindowsCE.Forms.Notification
    
                                this.notification1 = new Microsoft.WindowsCE.Forms.Notification();
    
  4. Fügen Sie folgenden Code, das Click-Ereignis der Schaltfläche behandeln.

                                Private
                                Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
    
        ' Use a StringBuilder for better performance.Dim HTMLString AsNew 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()
    
        Dim IconStream AsNew 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
    EndSub
    
                                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. Fügen Sie folgenden Code für die Ereignisbehandlung ResponseSubmitted.

                                ' When a ResponseSubmitted event occurs, this event handler
                                ' parses the response to determine values in the HTML form.
                                Private
                                Sub Notification1_ResponseSubmitted(ByVal sender AsObject, _
        ByVal resevent As Microsoft.WindowsCE.Forms.ResponseSubmittedEventArgs) _
        Handles Notification1.ResponseSubmitted
    
        If resevent.Response.Substring(0,6) = "notify"Then        ' Add code here to respond to the notification.EndIfEndSub
    
                                // 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.
            }
        };
    

Kompilieren des Codes

In diesem Beispiel sind Verweise auf die folgenden Namespaces erforderlich:

Siehe auch

Aufgaben

Notification Sample

Referenz

Notification

Weitere Ressourcen

Pocket PC-Entwicklung und .NET Compact Framework