现在的位置: 首页 > 综合 > 正文

NETCF开发之Notification控件

2013年03月18日 ⁄ 综合 ⁄ 共 2547字 ⁄ 字号 评论关闭

1.1    Notification控件

Notification控件是.NET Compact Framework 2.0提供的新控件之一。Notification实现用于显示和响应用户通知的功能。如图4-13所示,使用Notification控件询问用户是否开始下载。

 


4-13Notification控件

 

4-2列出了Notification控件的主要属性。

 

4-2Notification的主要属性

属性

说明

Caption

获取或设置指定消息气球的标题文本的字符串。

Critical

获取或设置一个值,指示通知是否非常重要。

Icon

获取或设置标题栏上的消息气球的当前图标。

InitialDuration

获取或设置消息气球首次显示之后保持可见的秒数。

Text

获取或设置消息气球的文本。

Visible

获取或设置一个值,用以指示消息气球是否可见。

 

创建通知后,可设置Visible属性控制是否显示通知。InitialDuration属性设置消息气球最初显示的时间。如果将InitialDuration设置为零,并将Visible设置为 true,则消息气球不会显示,但是标题栏中会有它的图标,单击可以重新激活它。通知除了能够显示纯文本之外,还可以在消息气球中创建HTML内容的用户通知。清单4-3演示创建并显示如图4-13所示的HTML内容的通知。

 

清单 4-3        创建并显示HTML内容的通知


……

Dim HTMLString As New Text.StringBuilder

        Dim sPath As String

 

        sPath = System.IO.Path.GetDirectoryName(_

Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString())

 

        HTMLString.Append("<html><body>")

        HTMLString.Append("<font color=""#0000FF"">Data ready to download</font>")

        HTMLString.Append("&nbsp;&nbsp;<a href=""settings"">Settings</a>")

        HTMLString.Append("<br><form method=""GET"" action=notify>")

        HTMLString.Append("<SELECT NAME=""lstbx"">")

        HTMLString.Append("_

<OPTION VALUE=""0"">Start now</OPTION><OPTION VALUE=""1"">In 1 hr</OPTION>")

        HTMLString.Append("_

<OPTION VALUE=""2"">In 2 hrs</OPTION><OPTION VALUE=""3"">In 3 hrs</OPTION>")

        HTMLString.Append("<OPTION VALUE=""4"">In 4 hrs</OPTION></SELECT>")

        HTMLString.Append("<input type=checkbox name=chkbx>Notify completion")

        HTMLString.Append("<br><input type='submit'>")

        HTMLString.Append("<input type=button name='cmd:2' value='Cancel'>")

        HTMLString.Append("</body></html>")

 

        ' 设置Text属性

        Notification1.Text = HTMLString.ToString()

 

        Dim IconStream As New IO.FileStream(sPath + "/info.ico", _

IO.FileMode.Open, IO.FileAccess.Read)

        Notification1.Icon = New Drawing.Icon(IconStream, 16, 16)

        Notification1.Caption = "Notification Demo"

        Notification1.Critical = False

 

        ' 设置气球显示时间

        Notification1.InitialDuration = 10

        Notification1.Visible = True

……

 

 

4-3列出了Notification控件的主要事件。

 

4-3Notification的主要事件

事件

说明

BalloonChanged

在显示或隐藏消息气球时发生。

ResponseSubmitted

在用户单击消息气球中的按钮或链接时发生。

 

       每当显示或隐藏气球时,无论是使用Visible属性以编程方式进行此操作,还是通过用户交互方式进行此操作,都会触发BalloonChanged事件。通过编写处理ResponseSubmitted事件的代码,可以处理对通知的响应。清单4-4演示处理对通知的响应。

 

清单 4-4 处理对通知的响应


Private Sub Notification1_ResponseSubmitted(ByVal sender As System.Object, _

ByVal e As Microsoft.WindowsCE.Forms.ResponseSubmittedEventArgs) _

Handles Notification1.ResponseSubmitted

If e.Response.Substring(0, 6) = "notify" Then

Notification1.Visible = False

System.Windows.Forms.MessageBox.Show("提交成功")

End If

End Sub

 

 

抱歉!评论已关闭.