需要相当于vb.net的vb上的screen.width和screen.height

时间:2013-11-02 18:21:41

标签: vb.net

在VB6中,我有以下代码来停靠窗口:

Public Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    If IsBeingDragged = True And Button = MouseButtons.Left Then
        'if the drag flag is true and left mouse button is pressed...

        'set Left side  docking
        If Me.Left + (x - Xs) < DockScale Then
            Me.Left = 0
            Exit Sub
        End If
        'set Top side docking
        If Me.Top + (y - Ys) < DockScale Then
            Me.Top = 0
            Exit Sub
        End If

        'set right side docking
        If Me.Left + (x - Xs) + Me.Width > (Screen.Width - DockScale) Then
            Me.Left = Screen.Width - Me.Width
            Exit Sub
        End If

        'set bottom side docking
        If Me.Top + (y - Ys) + Me.Height > (Screen.Height - DockScale) Then
            Me.Top = Screen.Height - Me.Height
            Exit Sub
        End If

        'move the form finally
        Me.Left = Me.Left + (x - Xs)
        Me.Top = Me.Top + (y - Ys)
    End If
End Sub

我现在正在使用vb.net,当我尝试复制并粘贴我的代码告诉我screen.widht和screen.height不是systems.window.form.screen的成员,是否有相当于这个在vb.net上?

1 个答案:

答案 0 :(得分:1)

用于访问VB.NET中屏幕尺寸的示例代码:

Dim curScreen As Screen
curScreen = Screen.PrimaryScreen 'curScreen = Screen.AllScreens(0)
Dim height As Integer = curScreen.Bounds.Height
height = curScreen.WorkingArea.Height

您必须选择所需的屏幕,然后决定要处理的“框架”:Bounds(整个屏幕)或WorkingArea(整个屏幕不包括任务栏)。