Results 1 to 5 of 5

Thread: [RESOLVED] UserControl resizing form

  1. #1

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Resolved [RESOLVED] UserControl resizing form

    I made a custom caption bar control to replace the standard Windows caption bar. It's just a very basic one with images for the caption bar and close/maximize/minimize buttons.

    I used 2 images for the top left and right corners. I have one of the MousePointer's set to SE/NW and the other one to SW/NE. So when holding the mouse over the corners it shows the "size window" cursor.

    How would I have this resize the form when the mouse is moved from the top corners?

    I attached a screen shot.

    The caption bar at the top is the UserControl which is placed at the top of the form.

    I would guess the code would go into the imgTopRight_MouseMove() event but I'm not sure how to do it.
    Last edited by DigiRev; Mar 26th, 2007 at 02:55 AM.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: UserControl resizing form

    have a look at the thrown together example - it's a usercontrol acting as the top-right resizer for a form. This is the usercontrol code
    VB Code:
    1. Dim lX As Long, lY As Long
    2. Dim bResizing As Boolean
    3. Private WithEvents oParent As Form
    4.  
    5. Private Sub oParent_Resize()
    6.     UserControl.Extender.Left = oParent.ScaleWidth - UserControl.Extender.Width
    7.     oParent.Refresh
    8. End Sub
    9.  
    10. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    11.     Set oParent = UserControl.Parent
    12.     If Button = vbLeftButton Then
    13.         lY = Y
    14.         lX = X
    15.         bResizing = True
    16.     End If
    17. End Sub
    18.  
    19. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    20.     If bResizing Then
    21.         With UserControl.Parent
    22.             .Move .Left, .Top + (Y - lY), .Width + (X - lX), .Height - (Y - lY)
    23.         End With
    24.     End If
    25. End Sub
    26.  
    27. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    28.     bResizing = False
    29.     Set oParent = Nothing
    30. End Sub
    it's not meant to be an exact answer, but it shows you one way you could go about it.

    Attached Files Attached Files

  3. #3

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: UserControl resizing form

    Wow thanks bush. Works great.

  4. #4
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: [RESOLVED] UserControl resizing form

    It has a bug though when you resize it to the tiniest. It returns an invalid call or procedure. Otherwise, pretty neat stuff. Gotta save this code for future use. You rock bush!

    I edited your code a bit. It'll return to normal size when the user accidentally resize it to the smallest.

    VB Code:
    1. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If bResizing Then
    3.         With UserControl.Parent
    4.             If .Width < 2 Or .Height < 2 Then
    5.                 DoEvents
    6.                 .Width = 3000
    7.                 .Height = 3000
    8.                 bResizing = False
    9.             Else
    10.                   .Move .Left, .Top + (Y - lY), .Width + (X - lX), .Height - (Y - lY)
    11.             End If
    12.         End With
    13.     End If
    14. End Sub

  5. #5

    Thread Starter
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: [RESOLVED] UserControl resizing form

    Thanks zynder.

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