[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. :confused:
1 Attachment(s)
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:
Dim lX As Long, lY As Long
Dim bResizing As Boolean
Private WithEvents oParent As Form
Private Sub oParent_Resize()
UserControl.Extender.Left = oParent.ScaleWidth - UserControl.Extender.Width
oParent.Refresh
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set oParent = UserControl.Parent
If Button = vbLeftButton Then
lY = Y
lX = X
bResizing = True
End If
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bResizing Then
With UserControl.Parent
.Move .Left, .Top + (Y - lY), .Width + (X - lX), .Height - (Y - lY)
End With
End If
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bResizing = False
Set oParent = Nothing
End Sub
it's not meant to be an exact answer, but it shows you one way you could go about it.
Re: UserControl resizing form
Wow thanks bush. Works great. :thumb:
:wave:
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:
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bResizing Then
With UserControl.Parent
If .Width < 2 Or .Height < 2 Then
DoEvents
.Width = 3000
.Height = 3000
bResizing = False
Else
.Move .Left, .Top + (Y - lY), .Width + (X - lX), .Height - (Y - lY)
End If
End With
End If
End Sub
Re: [RESOLVED] UserControl resizing form