Mouse Drag to change textbox position on fly (1 Viewer)

Babycat

Member
Local time
Today, 18:18
Joined
Mar 31, 2020
Messages
275
Hi all

I know it is weird but I would like to know if any example or solution that able to change position of a form's control by mouse click and drag in form view mode?
I studied about on mousemove event and try to set new position when event fired, but it seems to be exhausted...

My end-user wants to change a textbox position on fly - when access program is running
 

June7

AWF VIP
Local time
Today, 03:18
Joined
Mar 9, 2014
Messages
5,423
Need code that would get cursor positions. That is fairly easy https://support.microsoft.com/en-us...position-1ef41d8b-6348-6ef1-f015-f9119799c65c
I had to change Hold variable to Public in module header so form code could read it.

Use difference of start cursor and end cursor locations to adjust textbox Top and Left properties.

Textbox MouseDown event can capture starting cursor location.
What I can't figure out is where to put code to capture ending cursor location.
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 04:18
Joined
Oct 29, 2018
Messages
21,357
I've seen a demo before for dragging a textbox around. Try searching for a restaurant seating chart demo. I'll let you know if I find it again.
 

jdraw

Super Moderator
Staff member
Local time
Today, 07:18
Joined
Jan 23, 2006
Messages
15,361
My end-user wants to change a textbox position on fly - when access program is running
What sort of application is this? Seems a strange requirement-- I don't think I've seen a requirement to move controls during execution, but.........
Here is example from ChrisO (RIP) where he showed drag and drop but it was demonstrating drag and drop and not a specific application requirement.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:18
Joined
Feb 19, 2013
Messages
16,553
this is a simple example. Just has the basic minimum requirements. Note the use of insideheight and insidewidth to prevent moving the control off the form (which would cause an error). If your form has sections then the insideheight need to be replaced to reference the relevant section - controls cannot be moved to a different section in form view.

If this is a permanent change requirement, then you will need code in the mouse up event or form close event to get the control's left and top values and store in a table and when the form is opened, reference that table to position the control accordingly
 

Attachments

  • dbMoveCtrl.zip
    20.5 KB · Views: 249

Babycat

Member
Local time
Today, 18:18
Joined
Mar 31, 2020
Messages
275
What sort of application is this? Seems a strange requirement-- I don't think I've seen a requirement to move controls during execution, but.........
Here is example from ChrisO (RIP) where he showed drag and drop but it was demonstrating drag and drop and not a specific application requirement.

My friend is working at event organizer, he wants to change position of company name or logo on the backdrop.
The backdrop is actually an access from.
 

Babycat

Member
Local time
Today, 18:18
Joined
Mar 31, 2020
Messages
275
this is a simple example. Just has the basic minimum requirements. Note the use of insideheight and insidewidth to prevent moving the control off the form (which would cause an error). If your form has sections then the insideheight need to be replaced to reference the relevant section - controls cannot be moved to a different section in form view.

If this is a permanent change requirement, then you will need code in the mouse up event or form close event to get the control's left and top values and store in a table and when the form is opened, reference that table to position the control accordingly

I tried your db, it works like a champ. I initially had same idea, but somehow it was not working smooth. Will study our code.

Thank everyone for helping me.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:18
Joined
May 7, 2009
Messages
19,169
this is a simple example.
you need to adjust the code.
if you drag it too fast (left or right), it randomly stop, but not on the Edge (left or right) of the window.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:18
Joined
Feb 19, 2013
Messages
16,553
you need to adjust the code.
I'm not in the business of providing fully working code on this or other forums - it's intended as an example to demonstrate how it can be done. There is limited error checking and if someone wants a fully developed, commercially sound chunk of code, they can pay for it. I'm sure the OP is perfectly capable of adding their own error checking if required. The same applies to the second example I provided.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:18
Joined
May 7, 2009
Messages
19,169
here is a working move/resize textbox.
it can be modified to use other controls that can
accept mouse events.

No need for you to pay or add attribution.
use it as your own.
 

Attachments

  • MoveResizeTextboxClass.accdb
    6.3 MB · Views: 243

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:18
Joined
May 7, 2009
Messages
19,169
as noted by Adam on sample database forum.
 

Attachments

  • MoveResizeTextboxClass.accdb
    476 KB · Views: 246

Babycat

Member
Local time
Today, 18:18
Joined
Mar 31, 2020
Messages
275
as noted by Adam on sample database forum.
Thank Arnelgp

In fact with CJ's code earlier, I have developed my own set, and I am able to resize the box too.
My trick is force user to press Shift key when they want to resize. It is not as great as yours but it is acceptable.

I need to study alot more since I viewed your code but not undertand them well. On designview mode, there is no event handle assigned to your textbox, but somehow it is still do the job...
 

Users who are viewing this thread

Top Bottom