WinForms MDI “Desktop” Area Boundary
Pergunta
O controle MDI pai padrão tem uma grande área "desktop" que pode exibir vários formulários filho. Os usuários podem arrastar formas para a borda desta área desktop de modo que a maior parte do formulário filho é fora da tela. (A barra de rolagem, em seguida, aparece no pai MDI) eu não gosto desse recurso. Existe uma maneira de bloquear a borda da área de trabalho para que os formulários filho permanecer totalmente visível?
Solução
- Desativar as barras de rolagem janela MDI
- ligar o evento OnMove de todas as janelas filho. Se a janela é movida fora do limite, "pop" de volta ao longo do X e Y até que ele está de volta dentro do pai.
Outras dicas
O código que usei para implementar a resposta que eu selecionado acima:
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
Para esclarecer, o que você diz é a área "desktop" do cliente MDI é a área do cliente.
Você poderia lidar com os manipuladores Resize / Move caso de formulários filho e, em seguida, redimensionar / restringir o movimento da criança quando ultrapassa os limites da área de cliente MDI.