I'm using this code which allows me to dock a form. However what i need is a way to when the form is docked to either side of the screen the form will adopt the height of the screen and when i move to either the top or the bottom of the screen it addopts the width. Does anyone know how i would intergrate this?

VB Code:
  1. 'Form declaration section
  2. Dim Xs As Integer               'Change in X
  3. Dim Ys As Integer               'Change in Y
  4. Dim IsBeingDragged As Boolean   'Flag if the form is being dragged
  5. Dim DockScale As Integer        'Scale by which the form docks itself to screen
  6.  
  7. Private Sub Form_Load()
  8. 'set form docking scale (change it according to your needs)
  9. DockScale = 200
  10. End Sub
  11. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  12. 'set flag to true
  13. IsBeingDragged = True
  14. 'get X Change and Y Change
  15. Xs = x
  16. Ys = y
  17. End Sub
  18. Public Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  19. If IsBeingDragged = True And Button = vbLeftButton Then
  20.     'if the drag flag is true and left mouse button is pressed...
  21.    
  22.     'set Left side  docking
  23.     If Form1.Left + (x - Xs) < DockScale Then
  24.         Form1.Left = 0
  25.         Exit Sub
  26.     End If
  27.     'set Top side docking
  28.     If Form1.Top + (y - Ys) < DockScale Then
  29.         Form1.Top = 0
  30.         Exit Sub
  31.     End If
  32.    
  33.     'set right side docking
  34.     If Form1.Left + (x - Xs) + Form1.Width > (Screen.Width - DockScale) Then
  35.         Form1.Left = Screen.Width - Form1.Width
  36.         Exit Sub
  37.     End If
  38.    
  39.     'set bottom side docking
  40.     If Form1.Top + (y - Ys) + Form1.Height > (Screen.Height - DockScale) Then
  41.         Form1.Top = Screen.Height - Form1.Height
  42.         Exit Sub
  43.     End If
  44.    
  45.     'move the form finally
  46.     Form1.Left = Form1.Left + (x - Xs)
  47.     Form1.Top = Form1.Top + (y - Ys)
  48. End If
  49. End Sub
  50. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  51.     'set drag flag to false
  52.     IsBeingDragged = False
  53. End Sub

Regards


Carl