关于 vb.net:Winforms MSI \\”Desktop\\” 区域边界

Winforms MDI "Desktop" Area Boundry

默认的 MDI 父控件有一个很大的"桌面"区域,可以显示多个子窗体。用户可以将表单拖到这个桌面区域的边缘,这样子表单的大部分就不会出现在屏幕上。 (然后滚动条出现在 MDI 父级中)我不喜欢这个功能。有没有办法锁定桌面区域的边缘以使子窗体保持完全可见?


我用来实现上面选择的答案的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Public alreadyMoved As Boolean = False
Public Const HEIGHT_OF_MENU_STATUS_BARS As Integer = 50
Public Const WIDTH_OF_MENU_STATUS_BARS As Integer = 141
Private Sub Form_Move(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Move
    If Not alreadyMoved Then
        alreadyMoved = True

        'If I'm over the right boundry, drop back to right against that edge
        If Me.Location.X + Me.Width > _
            MdiParent.ClientRectangle.Width - WIDTH_OF_MENU_STATUS_BARS Then
            MyBase.Location = New System.Drawing.Point( _
                (MdiParent.ClientRectangle.Width - Me.Width - _
                WIDTH_OF_MENU_STATUS_BARS), MyBase.Location.Y)
        End If

        'If I'm over the bottom boundry, drop back to right against that edge
        If Me.Location.Y + Me.Height > _
            MdiParent.ClientRectangle.Height - HEIGHT_OF_MENU_STATUS_BARS Then
            MyBase.Location = New System.Drawing.Point( _
                MyBase.Location.X, (MdiParent.ClientRectangle.Height - _
                Me.Height - HEIGHT_OF_MENU_STATUS_BARS))
        End If

        'If I'm over the top boundry, drop back to the edge
        If Me.Location.Y < 0 Then
            MyBase.Location = New System.Drawing.Point(MyBase.Location.X, 0)
        End If

        'If I'm over the left boundry, drop back to the edge
        If Me.Location.X < 0 Then
            MyBase.Location = New System.Drawing.Point(0, MyBase.Location.Y)
        End If
    End If
    alreadyMoved = False
End Sub

  • 禁用 MDI 窗口滚动条
  • 挂钩所有子窗口的 OnMove 事件。如果窗口移动到边界之外,则沿 x 和 y 将其"弹出"回,直到它回到父级内部。

  • 澄清一下,你所说的MDI客户端的"桌面"区域就是客户区。

    您可以处理子窗体的调整大小/移动事件处理程序,然后在子窗体超出 MDI 客户区域的范围时调整大小/限制其移动。