|
-
Sep 11th, 2009, 12:17 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Excel: Detect movement of UserForm
Is there any way to detect that a modeless UserForm has been moved by a mouse click/drag in the title area? UserForm_MouseMove and UserForm_MouseUp appear to work only with buttons.
When a Userform is moved, it comes in focus. I want to detect the move and somehow remove the focus.
-
Sep 11th, 2009, 01:13 PM
#2
Re: Excel: Detect movement of UserForm
When a Userform is moved, it comes in focus. I want to detect the move and somehow remove the focus.
Do you mean you don't want the user to move the userform?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 11th, 2009, 02:15 PM
#3
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
No, it's related to my post from yesterday.
http://www.vbforums.com/showthread.php?t=583746
The userform is displayed when a cell is clicked. The intent is to fill the cell by picking an item from a listbox within the userform. But, while the userform is displayed I want keyboard keys like PgUp and the arrows keys to function normally. I've figured out how to do this by using AppActivate ("Microsoft Excel") whenever the userform is displayed, which changes the focus from the userform back to the sheet cell. So far so good.
Now, if the userform is moved, the focus moves back to the userform, which means pressing PgUp or an arrow key selects an item in the listbox. I want to restrict listbox selection to mouse only. My thought was that by detecting the movement of the userform, I can once again use AppActivate ("Microsoft Excel") to set the focus back to the sheet.
Hope this makes sense.
-
Sep 11th, 2009, 03:06 PM
#4
Re: Excel: Detect movement of UserForm
I have been fighting with the mouse API's for the last 2 hrs but I am still stuck...
There is one option though.. Creating a userform without the title bar... Then I guess it would be easy to achieve what you want...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 11th, 2009, 03:18 PM
#5
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
Hmmmm. Which mouse API's?
-
Sep 11th, 2009, 03:20 PM
#6
Re: Excel: Detect movement of UserForm
There is one option though.. Creating a userform without the title bar... Then I guess it would be easy to achieve what you want...
Yes! i tried it and it is possible... let me know if you are interested...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 11th, 2009, 03:24 PM
#7
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
I need to keep the titles. What mouse API's were you toying with?
-
Sep 11th, 2009, 03:26 PM
#8
Re: Excel: Detect movement of UserForm
 Originally Posted by VBAhack
I need to keep the titles. What mouse API's were you toying with?
http://www.google.co.in/#hl=en&sourc...bff82df9e80f1a
Btw you can always use the labels to show the title
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 11th, 2009, 03:39 PM
#9
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
I use the caption property of the userform to display the title. Is that what you mean by label?
-
Sep 11th, 2009, 03:43 PM
#10
Re: Excel: Detect movement of UserForm
yes. would you like to see what I have got?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 11th, 2009, 03:49 PM
#11
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
Seem to be running out of possibilities........
1. There's no event associated with clicking in the caption area of a userform or for changing the position of the userform
2. There doesn't appear to be a mouse event API that fires when a mouse is clicked or moved. I can get the mouse position via API and simulate a mouse click, but not detect a mouse click or movement.
3. There's no "before key press" event
-
Sep 11th, 2009, 03:50 PM
#12
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
 Originally Posted by koolsid
yes. would you like to see what I have got?
Sure, I'd be interested. Might learn something. Thanks.
-
Sep 11th, 2009, 04:04 PM
#13
-
Sep 11th, 2009, 09:40 PM
#14
Re: Excel: Detect movement of UserForm
try userform layout event
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 11th, 2009, 10:01 PM
#15
Re: Excel: Detect movement of UserForm
Yeah Pete, I tried that as well last night. The only Problem is that this event doesn't wait for me to finish my dragging. It simply runs when I am holding the title bar (with the mouse of course )
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 12th, 2009, 12:40 AM
#16
Re: Excel: Detect movement of UserForm
could use some sort of timer to wait for the event to stop firing for some length time
i tried like
vb Code:
Private Sub UserForm_Layout() If Not wait Then wait = True mleft = Left Application.OnTime Now + TimeValue("00:00:01"), "unwait" Debug.Print Me.Left End If End Sub ' in a module Public wait As Boolean Public mleft As Integer Public Sub unwait() MsgBox "moved " & Abs(UserForm1.Left - mleft) wait = False End Sub
it fired on activate, which i am sure could be avoided
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 14th, 2009, 01:01 PM
#17
Thread Starter
Fanatic Member
Re: Excel: Detect movement of UserForm
 Originally Posted by westconn1
try userform layout event
Layout event does the trick! Thanks westconn1! I don't really care if it fires a couple of times.
Code:
Private Sub UserForm_Layout()
AppActivate ("Microsoft Excel")
End Sub
Thanks koolsid, that was some pretty clever work! Substituting a label button for the title and then capturing the mouse move event. That approach has a desireable side effect that the button to dismiss the form can easily be hidden.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|