学院首页>网络编程>ASP.NET>VS.NET 2005 Beta2初体验(4)-Notification控件

VS.NET 2005 Beta2初体验(4)-Notification控件

作者: 来源: 添加时间:2006-5-21 19:36:54
今天的主题是Notification,这是Windows CE所特有的一种消息通知方式。消息支持文本和HTML形式,当有消息出现的时候会出现一个气泡式的窗体。在以前的VS.NET 2003里,发送Notification,的主要方式是调用API或者使用OpenNETCF中的相关类。而.NET CF 2.0目前支持了托管方式的Notification。

我们首先在工具栏里找到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();

  }

   }

站内搜索