質問

デフォルトのMDI親コントロールには、大きな「デスクトップ」があります。複数の子フォームを表示できる領域。ユーザーはフォームをこのデスクトップ領域の端にドラッグして、ほとんどの子フォームが画面から外れるようにすることができます。 (MDI親にスクロールバーが表示されます)この機能が気に入らない。子フォームが完全に表示されるように、デスクトップ領域の端をロックダウンする方法はありますか?

役に立ちましたか?

解決

  1. MDIウィンドウのスクロールバーを無効にする
  2. すべての子ウィンドウのOnMoveイベントをフックします。ウィンドウが境界の外側に移動した場合、「ポップ」親の内部に戻るまでxとyに沿って戻ります。

他のヒント

上記で選択した回答を実装するために使用したコード:

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クライアントの領域はクライアント領域です。

子フォームのサイズ変更/移動イベントハンドラーを処理し、MDIクライアント領域の境界を超えたときに子の移動をサイズ変更/制限できます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top