ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving a label on a form at run time. (https://www.excelbanter.com/excel-programming/422432-moving-label-form-run-time.html)

Tony

Moving a label on a form at run time.
 
Is there a way to allow a user to move (drag and drop) a text box or a label
on an open form? I want the user to be able to place a "note" on the form,
but once the box opens, I need them to be able to move it around on the page
similar to the way one can move a Post It note. I am running Excel 2003.

Tony


Leith Ross[_724_]

Moving a label on a form at run time.
 

Hello Tony,

Where are these objects? On a worksheet or a VBA UserForm?

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=50104


Harald Staff[_2_]

Moving a label on a form at run time.
 
Hi Tony

Here on a Userform, dragging Label1 around:

Option Explicit ' *********** top pof module ************

Dim x0 As Long, y0 As Long

Private Sub Label1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
x0 = X
y0 = Y
End Sub

Private Sub Label1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
Label1.Top = Label1.Top + Y - y0
Label1.Left = Label1.Left + X - x0
End If
End Sub

HTH. Best wishes Harald

"Tony" wrote in message
...
Is there a way to allow a user to move (drag and drop) a text box or a
label on an open form? I want the user to be able to place a "note" on the
form, but once the box opens, I need them to be able to move it around on
the page similar to the way one can move a Post It note. I am running
Excel 2003.

Tony



Jon Peltier

Moving a label on a form at run time.
 
Harald -

Pretty cool, as always. I made some refinements to keep the label within the
confines of the userform:

'''''''''''''''''''''''''''
Option Explicit

Dim x0 As Long, y0 As Long

Private Sub Label1_MouseDown(ByVal Button As Integer, _

ByVal Shift As Integer, _

ByVal X As Single, ByVal Y As Single)


x0 = X

y0 = Y


End Sub

Private Sub Label1_MouseMove(ByVal Button As Integer, _

ByVal Shift As Integer, _

ByVal X As Single, ByVal Y As Single)


Dim x1 As Long, y1 As Long


If Button = 1 Then

x1 = Label1.Left + X - x0

If x1 < 0 Then x1 = 0

If x1 Me.InsideWidth - Me.Label1.Width Then

x1 = Me.InsideWidth - Me.Label1.Width

End If


y1 = Label1.Top + Y - y0

If y1 < 0 Then y1 = 0

If y1 Me.InsideHeight - Me.Label1.Height Then

y1 = Me.InsideHeight - Me.Label1.Height

End If


Label1.Left = x1

Label1.Top = y1

End If


End Sub

'''''''''''''''''''''''''''

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______


"Harald Staff" wrote in message
...
Hi Tony

Here on a Userform, dragging Label1 around:

Option Explicit ' *********** top pof module ************

Dim x0 As Long, y0 As Long

Private Sub Label1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
x0 = X
y0 = Y
End Sub

Private Sub Label1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
Label1.Top = Label1.Top + Y - y0
Label1.Left = Label1.Left + X - x0
End If
End Sub

HTH. Best wishes Harald

"Tony" wrote in message
...
Is there a way to allow a user to move (drag and drop) a text box or a
label on an open form? I want the user to be able to place a "note" on
the form, but once the box opens, I need them to be able to move it
around on the page similar to the way one can move a Post It note. I am
running Excel 2003.

Tony






All times are GMT +1. The time now is 05:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com