次の方法で共有


方法 : 通知を送信する

更新 : 2007 年 11 月

アプリケーションでユーザーにアクション (データを送信するように求めるなど) を実行させなければならない場合は、いつでも Notification を使用できます。通常は、イベントが発生したり条件が満たされたときに通知を送信します。この例では、より簡単にするためにボタンがクリックされると通知を表示します。ResponseSubmitted イベントを処理するコードを使用することで、通知への応答を処理できます。

通知内のメッセージは、プレーン テキストまたは HTML 形式となります。HTML の場合は、チェック ボックス、ボタン、リスト、およびその他の HTML 要素を含む小さな HTML フォームを送信できます。この例では、[送信] および [キャンセル] ボタンのある簡単なフォームを使用します。

[キャンセル] ボタンは、"cmd:2" で識別されます。Windows CE では、通知を閉じるために使用します。cmd:2 が HTML ボタンまたはその他の要素の名前に使用されている場合は、ResponseSubmitted イベントが発生しません。通知は閉じられますが、そのアイコンはタイトル バーに配置され、後で応答できます。

通知を送信するには

  1. Pocket PC Windows アプリケーションを作成します。

  2. フォームに Notification および Button を追加します。

  3. Notification インスタンスを作成します。

    Me.Notification1 = New Microsoft.WindowsCE.Forms.Notification
    
    this.notification1 = new Microsoft.WindowsCE.Forms.Notification();
    
  4. ボタンの Click イベントを処理する次のコードを追加します。

    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 As 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()
    
        Dim IconStream As 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
    End Sub 
    
    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. 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 As Object, _
        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.
        End If
    
    End Sub
    
    // 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.
            }
        };
    

コードのコンパイル方法

この例は、次の名前空間への参照を必要とします。

参照

処理手順

通知のサンプル

参照

Notification

その他の技術情報

Pocket PC の開発と .NET Compact Framework