Detecting form movement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kiteman - Canada

    #1

    Detecting form movement

    Is there an event triggered when a form is dragged by its titlebar?

    I have two forms on screen - the main form is draggable and I need the
    secondary form to automatically reposition itself adjacent to the main form
    if the main form is relocated.

    Tom


  • Raoul Watson

    #2
    Re: Detecting form movement


    "Kiteman - Canada" <-delete-kiteman@shaw.ca > wrote in message
    news:sNxjc.2718 88$Pk3.212594@p d7tw1no...[color=blue]
    > Is there an event triggered when a form is dragged by its titlebar?
    >
    > I have two forms on screen - the main form is draggable and I need the
    > secondary form to automatically reposition itself adjacent to the main[/color]
    form[color=blue]
    > if the main form is relocated.
    >
    > Tom
    >[/color]
    Without subclassing the window, all I can think of is save Me.left and
    me.top on form activate.

    Have a timer event that checks If Me.Left <> oldleft Or Me.Top <> oldtop
    Then <form has been moved>



    Comment

    • Kiteman - Canada

      #3
      Re: Detecting form movement

      Raoul, thanks for the reply. I tried your timer method and it works like a
      charm. I wanted the repositioning of the second form to happen quicker, so
      I turned down the Interval on the timer from 500 down to 20 and was unhappy
      with the CPU intensity....so ....

      I made the Main form non-draggable and created a text lbl called lblDragForm
      on the form called 'Main' and I can just left or right click and hold on
      that label. I then created the following code:

      Public Sub lblDragForm_Mou seDown(Button As Integer, Shift As Integer, X As
      Single, Y As Single)
      'When left mouse button is pressed over Drag box enable dragging
      MoveTheForm = True ' Drag is enabled
      'Locate where on the Drag box the user has clicked and remember that
      position for the lblDragForm routine
      StartX = X
      StartY = Y
      End Sub

      Public Sub lblDragForm_Mou seUp(Button As Integer, Shift As Integer, X As
      Single, Y As Single)
      'When left mouse button is released stop the drag and force form to be
      within screen borders
      MoveTheForm = False ' Drag is disabled
      If Main.Left < 0 Then Main.Left = 0
      If Main.Top < 0 Then Main.Top = 0
      If Main.Top + Main.Height > Screen.Height Then _
      Main.Top = Screen.Height - Main.Height
      If Main.Left + Main.Width > Screen.Width Then _
      Main.Left = Screen.Width - Main.Width
      Call RefreshVisibleF orm
      End Sub

      Public Sub lblDragForm_Mou seMove(Button As Integer, Shift As Integer, X As
      Single, Y As Single)
      'This routine loops while LMB is depress over the Drag box and the mouse is
      moved
      If MoveTheForm Then
      Main.Left = Main.Left - StartX + X
      Main.Top = Main.Top - StartY + Y
      Call RefreshVisibleF orm
      End If
      End Sub


      Private Sub RefreshVisibleF orm()
      Select Case ComboMenu.ListI ndex
      Case 0
      frmIntroduction .Top = Main.Top + VerticalOffset
      frmIntroduction .Left = Main.Left
      frmIntroduction .Show
      Case 1
      frmMaterialsReq uired.Top = Main.Top + VerticalOffset
      frmMaterialsReq uired.Left = Main.Left
      frmMaterialsReq uired.Show
      Case 2
      frmGettingStart ed.Top = Main.Top + VerticalOffset
      frmGettingStart ed.Left = Main.Left
      frmGettingStart ed.Show

      <snip>

      End Select
      End Sub

      This is an unconvential way of dragging a form, but if it works, why not!

      Tom

      "Raoul Watson" <WatsonR@Intell igenCIA.com> wrote in message
      news:cDzjc.4729 4$635.38740@nwr dny03.gnilink.n et...[color=blue]
      >
      > "Kiteman - Canada" <-delete-kiteman@shaw.ca > wrote in message
      > news:sNxjc.2718 88$Pk3.212594@p d7tw1no...[color=green]
      > > Is there an event triggered when a form is dragged by its titlebar?
      > >
      > > I have two forms on screen - the main form is draggable and I need the
      > > secondary form to automatically reposition itself adjacent to the main[/color]
      > form[color=green]
      > > if the main form is relocated.
      > >
      > > Tom
      > >[/color]
      > Without subclassing the window, all I can think of is save Me.left and
      > me.top on form activate.
      >
      > Have a timer event that checks If Me.Left <> oldleft Or Me.Top <> oldtop
      > Then <form has been moved>
      >
      >
      >[/color]


      Comment

      Working...