Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Sep 2002
    Location
    London, England
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Movable forms with no title bar (2000)

    Can I do something to a form that will allow it to be moved by the user even when the form has no border?

    I am trying to create a pop up form that people will use to compare the entries they have made on a grid with existing data. The existing data is displayed as a thin strip, one row deep in the pop-up form. Hopefully, when the pop-up form opens its columns will line upwith the columns in the grid. However, the users may want to move it from side to side. The problem I am having is that the pop-up form's title bar is as thick as the rows on the grid and so it is hard to tell when the pop-up form is lined up correctly. I can solve this by removing giving the form no border, so that it loses its title bar, but then it cannot be moved.

    Ian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Movable forms with no title bar (2000)

    Put the following declarations in a standard module (created by clicking New in the Modules tab of the database window:

    <img src=/w3timages/blueline.gif width=33% height=2>

    'To Simulate the Caption Move
    Public Declare Function apiReleaseCapture Lib "user32" _
    Alias "ReleaseCapture" () As Long

    Public Declare Function apiSendMessage Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

    <img src=/w3timages/blueline.gif width=33% height=2>

    Create the following procedure in the form module:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Sub HandleMouseDown()
    apiReleaseCapture
    Call apiSendMessage(Me.hWnd, WM_SysCommand, SC_Move_Mouse, 0)
    End Sub

    <img src=/w3timages/blueline.gif width=33% height=2>

    and call it on the On Mouse Down event of the detail section:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Sub Detail_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    HandleMouseDown
    End Sub

    <img src=/w3timages/blueline.gif width=33% height=2>

    If the user clicks in an empty part of the detail section, (s)he can drag the form around. You can call HandleMouseDown in the On Mouse Down event of controls on the form too, if you like.

  3. #3
    3 Star Lounger
    Join Date
    Sep 2002
    Location
    London, England
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Movable forms with no title bar (2000)

    Hi Hans,

    Thanks for your help. Unfortunately it didn't work. I pasted your code into the locations indicated and it seems to compile OK. I've put breakpoints in and the code steps through the on mouse down event handler and the HandleMouseDown sub (although it didn't go into the API stuff - posibly relevant?) , but the form stays where it is. I tried calling HandleMouseDown from the detail section and from the form itself, I've tried normal and no border forms, but none of the combinations worked.

    I'd love to know how to do this as I could use it elsewhere.

    Thanks again

    Ian

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Movable forms with no title bar (2000)

    Oops, I forgot two constants to go into the standard module, sorry about that:

    Public Const WM_SysCommand As Long = &H112
    Public Const SC_Move_Mouse As Long = &HF012&

    By the way, the On Mouse Down event is not suitable for breakpoints and single stepping.

    Note:

    If you didn't get an error message that WM_SysCommand and SC_Move_Mouse were not defined, you apparently haven't set the "Require Variable Declaration" option in Tools | Options... in the Visual Basic Editor. Please do so now. This will add a line Option Explicit at the start of each new module. You will have to do this manually in existing modules. Option Explicit can save you a lot of trouble.

  5. #5
    3 Star Lounger
    Join Date
    Sep 2002
    Location
    London, England
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Movable forms with no title bar (2000)

    It worked. Thank you.

    On the Option Explicit thing, that is present already.

    Ian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •