PC Review


Reply
Thread Tools Rate Thread

Drag picture

 
 
youu917@gmail.com
Guest
Posts: n/a
 
      28th Jan 2008
can anyone tell me how to make the picture box in the excel form be
dragable by using VBA programming?
 
Reply With Quote
 
 
 
 
SteveM
Guest
Posts: n/a
 
      28th Jan 2008
On Jan 27, 8:41 pm, youu...@gmail.com wrote:
> can anyone tell me how to make the picture box in the excel form be
> dragable by using VBA programming?


youu,

I'm not sure you can do that because re-positioning and/or resizing a
form require it to be in edit mode. You could collect Left and Top
positions of the image object from the user to adjust it's position on
the form. But that would be clumsy.

Whenever anyone asks about these more exotic kinds of VBA
functionality, my first question is, "What value are you trying to
provide to the user?" Followed by, "Ts what you are trying to do
value-added from your and the user's perspective? And then step back
and see if you could deliver essentially the same value from an
alternative solution strategy or else try to persuade the customer to
reduce his requirements. (Time is money.)

Good Luck.

SteveM

P.S. to youu and anybody else who reads this thread, google "Occams
Razor". Read a few things about that and take note...
 
Reply With Quote
 
youu917@gmail.com
Guest
Posts: n/a
 
      28th Jan 2008
On Jan 28, 9:56*am, SteveM <sbm...@vzavenue.net> wrote:
> On Jan 27, 8:41 pm, youu...@gmail.com wrote:
>
> > can anyone tell me how to make the picture box in the excel form be
> > dragable by using VBA programming?

>
> youu,
>
> I'm not sure you can do that because re-positioning and/or resizing a
> form require it to be in edit mode. *You could collect Left and Top
> positions of the image object from the user to adjust it's position on
> the form. *But that would be clumsy.
>
> Whenever anyone asks about these more exotic kinds of VBA
> functionality, my first question is, "What value are you trying to
> provide to the user?" *Followed by, "Ts what you are trying to do
> value-added from your and the user's perspective? *And then step back
> and see if you could deliver essentially the same value from an
> alternative solution strategy or else try to persuade the customer to
> reduce his requirements. *(Time is money.)
>
> Good Luck.
>
> SteveM
>
> P.S. to youu and anybody else who reads this thread, google "Occams
> Razor". *Read a few things about that and take note...


thank you very much
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      28th Jan 2008
> can anyone tell me how to make the picture box in the excel
> form be dragable by using VBA programming?


You said "picture box", but I am going to assume you meant ImageBox. Place
an ImageBox (leave the default name of Image1) on the form. Copy/paste the
code below my signature into the UserForm's code window, run the project and
press Shift+<LeftMouseButton> to drag the ImageBox around the form.

Rick

Private OffsetX As Long, OffsetY As Long
Private Moving As Boolean

Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As _
Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 And Shift = 1 Then
OffsetX = X
OffsetY = Y
Moving = True
End If
End Sub

Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As _
Integer, ByVal X As Single, ByVal Y As Single)
If Moving Then
With Image1
.Move .Left + X - OffsetX, .Top + Y - OffsetY
End With
End If
End Sub

Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As _
Integer, ByVal X As Single, ByVal Y As Single)
Moving = False
End Sub

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      28th Jan 2008
> I'm not sure you can do that because re-positioning and/or resizing a
> form require it to be in edit mode. You could collect Left and Top
> positions of the image object from the user to adjust it's position on
> the form. But that would be clumsy.


See my response to the OP for a simple method to do what he asked.

Rick
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      28th Jan 2008

Rick,
Very nice, I will keep this one even though I may never use it.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"Rick Rothstein (MVP - VB)"
wrote in message
> can anyone tell me how to make the picture box in the excel
> form be dragable by using VBA programming?


You said "picture box", but I am going to assume you meant ImageBox. Place
an ImageBox (leave the default name of Image1) on the form. Copy/paste the
code below my signature into the UserForm's code window, run the project and
press Shift+<LeftMouseButton> to drag the ImageBox around the form.

Rick

Private OffsetX As Long, OffsetY As Long
Private Moving As Boolean

Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As _
Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 And Shift = 1 Then
OffsetX = X
OffsetY = Y
Moving = True
End If
End Sub

Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As _
Integer, ByVal X As Single, ByVal Y As Single)
If Moving Then
With Image1
.Move .Left + X - OffsetX, .Top + Y - OffsetY
End With
End If
End Sub

Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As _
Integer, ByVal X As Single, ByVal Y As Single)
Moving = False
End Sub

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      28th Jan 2008
> Very nice,

Thank you!

> I will keep this one even though I may never use it.


LOL

By the way, the procedure I posted is not restricted to ImageBox'es only;
you can use it with any control having those three Mouse events available.
For example, put a ListBox on the UserForm, copy/paste the code I posted
earlier, click Edit/Replace (or key in Ctrl+H) and replace all occurrence of
Image1 with ListBox1. Now, run the project and Shift+LeftMouseClick over the
ListBox and drag it around instead.

Rick


> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
>
>
>
>
> "Rick Rothstein (MVP - VB)"
> wrote in message
>> can anyone tell me how to make the picture box in the excel
>> form be dragable by using VBA programming?

>
> You said "picture box", but I am going to assume you meant ImageBox. Place
> an ImageBox (leave the default name of Image1) on the form. Copy/paste the
> code below my signature into the UserForm's code window, run the project
> and
> press Shift+<LeftMouseButton> to drag the ImageBox around the form.
>
> Rick
>
> Private OffsetX As Long, OffsetY As Long
> Private Moving As Boolean
>
> Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As _
> Integer, ByVal X As Single, ByVal Y As Single)
> If Button = 1 And Shift = 1 Then
> OffsetX = X
> OffsetY = Y
> Moving = True
> End If
> End Sub
>
> Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As _
> Integer, ByVal X As Single, ByVal Y As Single)
> If Moving Then
> With Image1
> .Move .Left + X - OffsetX, .Top + Y - OffsetY
> End With
> End If
> End Sub
>
> Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As _
> Integer, ByVal X As Single, ByVal Y As Single)
> Moving = False
> End Sub
>


 
Reply With Quote
 
youu917@gmail.com
Guest
Posts: n/a
 
      28th Jan 2008
Thank you very much! Appreciated that you solved my problem,thank you.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drag and Drop Picture =?Utf-8?B?QXN0cm9ib3k=?= Microsoft Excel Misc 1 11th Oct 2006 05:07 AM
How do I drag a picture to another spot on the same page? =?Utf-8?B?U3VwZXJfWF9TYXJhaA==?= Microsoft Word Document Management 2 29th Dec 2004 04:24 AM
Drag and drop a re-sized picture from excel to a picture box. =?Utf-8?B?Sm9obiBQLiBHcmVpbmVy?= Microsoft C# .NET 0 22nd Dec 2004 05:59 PM
Drag & Drop Bitmaps on a picture box Frank Microsoft Dot NET Framework 1 27th Apr 2004 10:10 AM
Why can't I drag a picture? Bert Coules Microsoft Word New Users 8 19th Apr 2004 07:50 PM


Features
 

Advertising
 

Newsgroups
 


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