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:
'Form declaration section Dim Xs As Integer 'Change in X Dim Ys As Integer 'Change in Y Dim IsBeingDragged As Boolean 'Flag if the form is being dragged Dim DockScale As Integer 'Scale by which the form docks itself to screen Private Sub Form_Load() 'set form docking scale (change it according to your needs) DockScale = 200 End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) 'set flag to true IsBeingDragged = True 'get X Change and Y Change Xs = x Ys = y End Sub Public Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) If IsBeingDragged = True And Button = vbLeftButton Then 'if the drag flag is true and left mouse button is pressed... 'set Left side docking If Form1.Left + (x - Xs) < DockScale Then Form1.Left = 0 Exit Sub End If 'set Top side docking If Form1.Top + (y - Ys) < DockScale Then Form1.Top = 0 Exit Sub End If 'set right side docking If Form1.Left + (x - Xs) + Form1.Width > (Screen.Width - DockScale) Then Form1.Left = Screen.Width - Form1.Width Exit Sub End If 'set bottom side docking If Form1.Top + (y - Ys) + Form1.Height > (Screen.Height - DockScale) Then Form1.Top = Screen.Height - Form1.Height Exit Sub End If 'move the form finally Form1.Left = Form1.Left + (x - Xs) Form1.Top = Form1.Top + (y - Ys) End If End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) 'set drag flag to false IsBeingDragged = False End Sub
Regards
Carl




Reply With Quote