我们首先在工具栏里找到Notification控件,并将它拖到窗体中,该控件将显示到窗体下面,和菜单控件在一起。
private void button1_Click(object sender, 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();
notification1.Caption = "Notification Demo";
notification1.Critical = false;
// Display icon up to 10 seconds.
notification1.InitialDuration = 10;
notification1.Visible = true;
}
我们在窗体上添加一个Button和一个TextBox,在Button的响应函数中加入上面的代码。这些代码是来自于MSDN。
然后我们再添加Notification控件的事件响应函数。选中Notification控件,在属性窗口中选择“事件”(那个闪电型的图标),然后双击ResponseSubmitted事件。
在事件处理函数中添加下面的代码:
private void notification1_ResponseSubmitted(object sender, Microsoft.WindowsCE.Forms.ResponseSubmittedEventArgs e)
{
if (e.Response.Substring(0, 6) == "notify")
{
// Add code here to respond to the notification.
textBox1.Text = e.Response.ToString();
}
}
……