다음을 통해 공유


방법: 알림 보내기

업데이트: 2007년 11월

데이터를 보내라는 메시지를 표시하는 것처럼 사용자가 응용 프로그램에서 작업을 수행해야 할 때마다 Notification을 사용할 수 있습니다. 일반적으로는 이벤트가 발생하거나 조건에 맞는 경우 알림 메시지를 보내지만 편의상 이 예제에서는 단추를 클릭할 때 알림 메시지를 표시합니다. ResponseSubmitted 이벤트를 처리하는 코드를 작성하여 알림 메시지에 대한 응답을 처리할 수 있습니다.

알림 메시지는 일반 텍스트 또는 HTML 형식일 수 있습니다. HTML 형식을 사용하면 확인란, 단추, 목록 및 다른 HTML 요소를 포함하는 작은 HTML 폼을 보낼 수 있습니다. 이 예제에서는 Submit 단추와 Cancel 단추가 포함된 간단한 폼을 사용합니다.

Cancel 단추는 "cmd:2"로 식별되고 Windows CE에서 알림 메시지를 해제할 때 사용됩니다. cmd:2가 HTML 단추의 이름 또는 메시지 풍선의 다른 요소인 경우에는 ResponseSubmitted 이벤트가 발생하지 않습니다. 알림은 해제되지만 제목 표시줄에 아이콘이 추가되어 나중에 응답할 수 있습니다.

알림을 보내려면

  1. Pocket PC Windows 응용 프로그램을 만듭니다.

  2. NotificationButton 컨트롤을 폼에 추가합니다.

  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