resize a Label by dragging

my problem is that i have to resize a label on my form by dragging its corner. please help me on this.
like if i'm going to move the cursor on the corner of the label, the cursor will change and it will allow me to drag its size.
[238 byte] By [jkcpineda] at [2007-11-20 11:09:49]
# 1 Re: resize a Label by dragging
The attached sample I put together might give you an idea and a start.
It's not perfect, though. Switching back to the vbDefault mousepointer seems to be a problem when you leave the label to the bottom right.

But how to drag size should be self explanatory. :)
WoF at 2007-11-9 19:33:50 >
# 2 Re: resize a Label by dragging
Try something like this :
Option Explicit

Dim bDown As Boolean
Dim MyX As Single
Dim MyY As Single

Dim MyWidth As Single
Dim MyHeight As Single

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= Label1.Left + Label1.Width Then
MyX = X
MyWidth = Label1.Left + Label1.Width
If Button = vbLeftButton Then bDown = True
End If

If Y >= Label1.Top + Label1.Height Then
MyY = Y
MyHeight = Label1.Top + Label1.Height
If Button = vbLeftButton Then bDown = True
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= Label1.Left + Label1.Width And X <= Label1.Left Then Me.MousePointer = 9 Else Me.MousePointer = 0
If bDown = True Then
Label1.Width = Label1.Width + X - MyX
MyX = X
End If

If Y >= Label1.Top + Label1.Height And Y <= Label1.Top Then Me.MousePointer = 7 Else Me.MousePointer = 0
If bDown = True Then
Label1.Height = Label1.Height + Y - MyY
MyY = Y
End If
End Sub

EDIT: So sorry WoF, I didn't see your great outstanding superb reply! :blush:
For some weird reason my IE didn't want to refresh! :eek:, I guess I should clear my Temporary Internet Files again :mad:
Sorry once again...
HanneSThEGreaT at 2007-11-9 19:34:50 >
# 3 Re: resize a Label by dragging
Nothing to be sorry about, Hannes.

Did you look at my sample?
It works fine. The only thing that bothers me is: if you move the mouse to the grab-corner (bottom right) the mousepointer changes as expected, but if you then move out of the label in the bottom right direction, the mouse pointer would not switch back to vbDefault. Any idea about that?
WoF at 2007-11-9 19:35:55 >
# 4 Re: resize a Label by dragging
Great code WoF!
OK, what I did to fix your little problem is to make use the Form's MouseDown event. In Form_MouseDown I just tested if the Dragging boolean is False then set the Form's MousePointer to vbDefault. Like this :
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Dragging Then Me.MousePointer = vbDefault
End Sub

So, if you just include that, your MousePointer does in fact update :)
HanneSThEGreaT at 2007-11-9 19:36:55 >
# 5 Re: resize a Label by dragging
Very good, Hannes. Didn't think about that.

The statement would have to go to the container object's MouseMove() routine, if the label is not on plain form but in a frame or a picture box.
WoF at 2007-11-9 19:37:54 >
# 6 Re: resize a Label by dragging
thanks to you both! you're great..
jkcpineda at 2007-11-9 19:38:50 >