ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving a control in a userform (https://www.excelbanter.com/excel-programming/317496-moving-control-userform.html)

Pierre Archambault

Moving a control in a userform
 
Hi everybody,

I would like to know how I could to allow a user to move a control (image)
in a userform.

Thanks

Pierre



Bob Phillips[_6_]

Moving a control in a userform
 
Pierre,

Add up and down, left and right buttons, and change the position. Here's
some code, it is a bit slow so you may want to try a spinner


Const hInc As Long = 4
Const vInc As Long = 4
Const hLeft As Long = 20
Const hRight As Long = 200
Const vTop As Long = 20
Const vBottom As Long = 300

Private Sub cmdLeft_Click()
With Me.Controls("Textbox1")
If .Left = hLeft Then
.Left = .Left - hInc
End If
End With
End Sub
Private Sub cmdRight_Click()
With Me.Controls("Textbox1")
If .Left <= hRight Then
.Left = .Left + hInc
End If
End With
End Sub
Private Sub cmdUp_Click()
With Me.Controls("Textbox1")
If .Top = vTop Then
.Top = .Top - vInc
End If
End With
End Sub
Private Sub cmdDown_Click()
With Me.Controls("Textbox1")
If .Top <= vBottom Then
.Top = .Top + vInc
End If
End With
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pierre Archambault" wrote in message
...
Hi everybody,

I would like to know how I could to allow a user to move a control (image)
in a userform.

Thanks

Pierre





Pierre Archambault

Moving a control in a userform
 
Thanks but I forgot to mention that the user uses only the mouse.
I also would like the mouse pointer to switch to a WE arrow when it reaches
the right end of the image and then be able to resize it while dragging
towards the left side.

Thank you
Pierre

"Bob Phillips" a écrit dans le message
de ...
Pierre,

Add up and down, left and right buttons, and change the position. Here's
some code, it is a bit slow so you may want to try a spinner


Const hInc As Long = 4
Const vInc As Long = 4
Const hLeft As Long = 20
Const hRight As Long = 200
Const vTop As Long = 20
Const vBottom As Long = 300

Private Sub cmdLeft_Click()
With Me.Controls("Textbox1")
If .Left = hLeft Then
.Left = .Left - hInc
End If
End With
End Sub
Private Sub cmdRight_Click()
With Me.Controls("Textbox1")
If .Left <= hRight Then
.Left = .Left + hInc
End If
End With
End Sub
Private Sub cmdUp_Click()
With Me.Controls("Textbox1")
If .Top = vTop Then
.Top = .Top - vInc
End If
End With
End Sub
Private Sub cmdDown_Click()
With Me.Controls("Textbox1")
If .Top <= vBottom Then
.Top = .Top + vInc
End If
End With
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pierre Archambault" wrote in message
...
Hi everybody,

I would like to know how I could to allow a user to move a control

(image)
in a userform.

Thanks

Pierre








All times are GMT +1. The time now is 10:35 AM.

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