Results 1 to 40 of 40

Thread: Move and Resize a Control or a Borderless Form - using window messages (smooth!)

Threaded View

  1. #33
    Member
    Join Date
    Sep 2010
    Location
    Huntsville, AL
    Posts
    62

    Re: Move and Resize a Control or a Borderless Form - using window messages (smooth!)

    I hate to resurrect an old thread, but I've started fooling with this code again. Pertaining to moving a control within a form, I've noticed that the cursor cannot be moved outside of the client rectangle of the form that the control is on. Does anyone know how windows determines the clip rectangle in this case? I feel that if we can specify the clip rectangle (maybe using ClipCursor) then we can handle the control's Min/Max size. If we are able to set the cursor clip, it would only take a little logic and math to get the clip rectangle right.

    Edit

    So I've managed to use the user32.dll ClipCursor function to limit the movement of the mouse. However, when your code calls the SendMessage function, the ClipCursor bounds are reset. I know almost nothing about the user32 functions, so I'm really over my head on this stuff. I'm guessing though, by the other posts, that it's just not possible. With my quick skim of the MSDN articles pertaining to user32.dll functions, it seems like it should be possible.

    Excerpts from your code (without the ClipCursor stuff, since it didn't work):
    Code:
        Private Sub MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
            If e.Button = Windows.Forms.MouseButtons.Left Then
                If resizeDir = ResizeDirection.None Then
                    If Me.AllowMoving Then MoveControl(_ctrl.Handle)
                Else
                    If (Me.AllowResizeFlags And resizeDir) = resizeDir Then
                        ResizeControl(_ctrl.Handle, resizeDir)
                    End If
                End If
            End If
        End Sub
    
        Private Sub ResizeControl(ByVal hWnd As IntPtr, ByVal direction As ResizeDirection)
            Dim dir As Integer = -1
    
            Select Case direction
                Case ResizeDirection.Left
                    dir = HTLEFT
                Case ResizeDirection.TopLeft
                    dir = HTTOPLEFT
                Case ResizeDirection.Top
                    dir = HTTOP
                Case ResizeDirection.TopRight
                    dir = HTTOPRIGHT
                Case ResizeDirection.Right
                    dir = HTRIGHT
                Case ResizeDirection.BottomRight
                    dir = HTBOTTOMRIGHT
                Case ResizeDirection.Bottom
                    dir = HTBOTTOM
                Case ResizeDirection.BottomLeft
                    dir = HTBOTTOMLEFT
            End Select
    
            If dir <> -1 Then
                ReleaseCapture()
                SendMessage(hWnd, WM_NCLBUTTONDOWN, dir, 0)
            End If
        End Sub
    Edit

    No ideas?
    Last edited by arcanine; Mar 16th, 2013 at 03:31 PM. Reason: Shameless bump.

Posting Permissions

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



Click Here to Expand Forum to Full Width