2009-03-02 8 views
4

既定のMDI親コントロールには、複数の子フォームを表示できる大きな「デスクトップ」領域があります。ユーザーはフォームをこのデスクトップ領域の端にドラッグすると、ほとんどの子フォームが画面外に表示されます。 (スクロールバーは、MDIの親に表示されます)私はこの機能が嫌いです。子フォームが完全に見えるように、デスクトップ領域の端を固定する方法はありますか?Winforms MDI "Desktop" Area Boundry

答えて

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

は、以下の私のコードはこれを実行するコードが含まれています参照してください。 – Jeff

3

あなたの言うことは、MDIクライアントの「デスクトップ」領域がクライアント領域であることです。

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

5

私は上記の選択された答えを実装するために使用されるコードに:

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