取得任务栏的大小和位置

由于任务栏可以随便拖放到屏幕的任意位置(上下左右其中之一),屏幕分辨率的不同任务栏的大小也不同。

下面的代码用来取得任务栏的大小和位置:

'''

''' 任务栏 ''' ''' Public Structure TaskBar Public Bounds As Rectangle Public DirectionF As Direction Public Enum Direction Bottom = 0 Left = 1 Top = 2 Right = 3 End Enum End Structure Public Function GetTaskBarRect() As TaskBar Dim tadkBarArea As New TaskBar '任务栏区域 Dim workingArea As Rectangle = Screen.GetWorkingArea(New Point(0, 0)) '工作区域 Dim screenArea As Rectangle = Screen.GetBounds(New Point(0, 0)) '主屏幕区域 '判断左上角位置以确定任务栏方向 With workingArea.Location If .X = 0 AndAlso .Y = 0 AndAlso workingArea.Width = screenArea.Width Then tadkBarArea.DirectionF = TaskBar.Direction.Bottom tadkBarArea.Bounds.X = 0 tadkBarArea.Bounds.Y = workingArea.Height tadkBarArea.Bounds.Width = workingArea.Width tadkBarArea.Bounds.Height = screenArea.Height - workingArea.Height ElseIf .X > 0 Then tadkBarArea.DirectionF = TaskBar.Direction.Left tadkBarArea.Bounds.X = 0 tadkBarArea.Bounds.Y = 0 tadkBarArea.Bounds.Width = screenArea.Width - workingArea.Width tadkBarArea.Bounds.Height = workingArea.Height ElseIf .X = 0 AndAlso .Y > 0 Then tadkBarArea.DirectionF = TaskBar.Direction.Top tadkBarArea.Bounds.X = 0 tadkBarArea.Bounds.Y = 0 tadkBarArea.Bounds.Width = workingArea.Width tadkBarArea.Bounds.Height = screenArea.Height - workingArea.Height ElseIf .X = 0 AndAlso .Y = 0 AndAlso workingArea.Height = screenArea.Height Then tadkBarArea.DirectionF = TaskBar.Direction.Right tadkBarArea.Bounds.X = workingArea.Right tadkBarArea.Bounds.Y = 0 tadkBarArea.Bounds.Width = workingArea.Width tadkBarArea.Bounds.Height = workingArea.Height End If End With Return tadkBarArea End Function

你可能感兴趣的:(VB.Net)