Dragging a control at runtime

J

JerryD

I would like the user to be able at runtime to drag an
image box to reposition it within a form. I would like
to write a routine so that the user could do this using
the mouse in the normal way of dragging. I know that I
will have to use the MouseDown and MouseMove events and I
have done similar programming in other languages, but I
can't figure out how to do this within Access. Or maybe
it is just not possible. Any ideas? Thanks.
 
R

Ron Weiner

Jerry

This has turned out to be MUCH harder to do than I expected. I thought I
could grab an Image controls hWnd on the MouseDown event an use the Win API
to have my way with it in the MouseMove event. However it turns out that
access controls do not have a hWnd. Apparently they are just drawn on to
the screen at run time. I found some code by Dev Ashish that is suppose to
get the hWnd of a control at run time
(http://www.mvps.org/access/api/api0027.htm), but in my test with an Access
unbound object frame it returned the hWnd of the form. During this
frustrating experience, I also discovered Image controls can not even get
the focus.

I was able to write some code that used all Access routines that would move
an Image control around, but it is herky, jerky and at least from my point
of view totally unusable.

Sooo.... If you'd like to move the whole darn form around by dragging on a
unbound Object frame I'm your man. Or if you want to frustrate the s--t out
of your users, I have a solution. As George Jetson use to say "It's gonna'
take a bigger brain than mine to figure this one out". Perhaps Stephen
Lebans could shed some light on this for us.

Ron W
 
S

Stephen Lebans

Over the past several years myself and a couple of others have posted
code enabling you to simulate dragging of Access lightweight(no
permanent DC) controls. Did you try a GoogleGroups search?

Here's some code to get you started but I'm sure I have seen more
polished code posted. The sample code uses a TextBox but it will work
for an Image control as well.

From: Stephen Lebans (nospam)
Subject: Re: Dragging controls at run-time


View this article only
Newsgroups: microsoft.public.access.forms
Date: 1999/12/22


Hi Ron,
you'll need to add some code to stop the user from trying to place the
control "outside" of the Form, so add some clipping boundary code. It's
time for bed so I haven't tested this much but it seems to work. Jeeze
you must have got a headache looking at that sample code you posted. I
thought I was back in the 80's for a moment there!<bg>

Option Compare Database
Option Explicit
Private mintOffsetX As Integer
Private mintOffsetY As Integer
Private mfMouseDown As Boolean
Private blFlag As Boolean


Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
With Text1 'Me.ActiveControl
.Locked = True
mintOffsetX = X - .Left
mintOffsetY = Y - .Top
End With
DoEvents
mfMouseDown = True

End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

If blFlag = True Then Exit Sub
blFlag = True
If mfMouseDown = True Then
With Text1 'Me.ActiveControl
.Left = .Left + X ' - mintOffsetX
.Top = .Top + Y '- mintOffsetY
End With
End If
DoEvents
blFlag = False


End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
mfMouseDown = False
Me.Text1.Locked = False 'Me.ActiveControl.Locked = False

End Sub

HTH



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
J

Jeff Bennett

JerryD said:
I would like the user to be able at runtime to drag an
image box to reposition it within a form. I would like
to write a routine so that the user could do this using
the mouse in the normal way of dragging. I know that I
will have to use the MouseDown and MouseMove events and I
have done similar programming in other languages, but I
can't figure out how to do this within Access. Or maybe
it is just not possible. Any ideas? Thanks.

As other respondants have indicated that this
is a tough problem when using just Access VBA,
I thought I might suggest an alternative approach
which may meet your needs.

Would you consider using a third party component within Access
to allow you to load multiple images into one control
and which will allow you with one line of code to enable
dragging ( and optionally resizing) of those images
by end-users.

If yes, then our MetaDraw control can do this.
You place MetaDraw on the Access form.
Then to load an image into MetaDraw
just write
MetaDraw.LoadPicture FileName, 2
You can load multiple image in this way,
Then you can position them by code with SetBounds method
or you can allow users to drag them around. Just set
the EditMode property
Metadraw.EditMode = 11
That's it.
You are done.

MetaDraw can be used on an Access Form and will also allow
scrolling, zooming, printing, saving and reloading the overall
layout, annotation, diagramming and much more.



-----

Jeff Bennett
(e-mail address removed)

* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* RELIABLE Components Make You Look Sharp!
* TList/Pro * ALLText HT/Pro * MetaDraw *
* Custom Software Development Services Too.
* WWW.Bennet-Tec.Com

=================== ===================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top