界面:
代码:
Public Class MyNamespce
Private strApplicationName As String = String.Empty
Public Property ApplicationName As String
Get
Return strApplicationName
End Get
Set(ByVal value As String)
strApplicationName = value
End Set
End Property
Public Event ApplicationCopyrightChanged(ByVal text As String)
Public Event ScreenBoundsChanged(ByVal bounds As Rectangle)
Public Event ScreenWorkingAreaChanged(ByVal bounds As Rectangle)
Private Sub btnApplicationCopyright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApplicationCopyright.Click
'显示应用程序的版权信息
RaiseEvent ApplicationCopyrightChanged(My.Application.Info.Copyright)
MessageBox.Show(My.Application.Info.Copyright, strApplicationName)
End Sub
Private Sub btnScreenBounds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScreenBounds.Click
'显示计算机屏幕的当前边界,这个边界由屏幕的分辨率设置决定
RaiseEvent ScreenBoundsChanged(My.Computer.Screen.Bounds)
MessageBox.Show(My.Computer.Screen.Bounds.ToString, strApplicationName)
End Sub
Private Sub btnScreenWorkingArea_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScreenWorkingArea.Click
'显示屏幕的当前工作区域。
RaiseEvent ScreenWorkingAreaChanged(My.Computer.Screen.WorkingArea)
MessageBox.Show(My.Computer.Screen.WorkingArea.ToString, strApplicationName)
End Sub
'计算任务栏高度
Public Function TaskBarHeight() As Integer
Return My.Computer.Screen.Bounds.Height - My.Computer.Screen.WorkingArea.Height
End Function
Protected Overrides Sub InitLayout()
MyBase.InitLayout()
If DesignMode Then
lblTime.Text = "设计模式"
Else
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lblTime.Text = Now.ToLongTimeString
End Sub
End Class
前台:
Public Class Form1
'显示任务栏高度
Private Sub btnTaskbarHeight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTaskbarHeight.Click
MessageBox.Show("Taskbar Height = " & MyNamespce1.TaskBarHeight & "pixels", "Form1")
End Sub
Private Sub MyNamespce1_ApplicationCopyrightChanged(ByVal text As String) Handles MyNamespce1.ApplicationCopyrightChanged
txtApplicationCopyright.Text = text
End Sub
Private Sub MyNamespce1_ScreenBoundsChanged(ByVal bounds As System.Drawing.Rectangle) Handles MyNamespce1.ScreenBoundsChanged
txtScreenBounds.Text = bounds.ToString
End Sub
Private Sub MyNamespce1_ScreenWorkingAreaChanged(ByVal bounds As System.Drawing.Rectangle) Handles MyNamespce1.ScreenWorkingAreaChanged
txtScreenWorkingArea.Text = bounds.ToString
End Sub
End Class