Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simutate click on vertical scrollbar by code

Status
Not open for further replies.

Gerrit Broekhuis

Programmer
Aug 16, 2004
316
NL
Hi,

For a Grid I need code to simulate (or execute) a click on the vertical scrollbar. The click position is not important.
How can I do this?

Regards, Gerrit
 
Hi Gerrit,
How about instead of telling us what you want to do here, tell us what you're trying to achieve.
The reason I say this is, vertical scroll bars in virtually any control all have the same behavior. So it sounds like you want to "do something" that's not typical/standard interface behavior. If we can understand more about what you're trying to achieve, we may know an alternative way to achieve what you're trying to do, and not just manage code on a scroll bar. (It sounds odd to me that you want to do this, so I am trying to understand the why and what you are trying to achieve).


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
Gerrit,

As Scott says, you really need to tell us exactly what you are trying to achieve.

If you simply want to scroll the grid programmatically, you use the grid's DoScroll method, specifying if you want to scroll up, down, left, right or whatever. See the Help for more details.

If that's not what you want, please give us some more information.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Scott and Mike,

All I needed was a “click on the scrollbar” This seemed to be needed to get some code working in a container MouseMove event. After a container resize the code was not immediately working.

I discovered today that “ThisForm.Grid.SetFocus()” was all that’s needed to get this working. Another problem solved!

Regards, Gerrit
 
Okay, I see ou solved it, but it's puzzling me why you try to simulate a scrollbar click when you actually need to trigger a mousemove event of a container. You can simulate a mouse move as you can do MOUSE AT x1,y1 DRAG TO x2,y2, that even triggers a mouse move if (x2,y2) = (x1,y1), so all you need is one coordinate in the container that's actuall causing this event on the container level (if you pick a coordinate that's on a control within the container, its MouseMove occurs.

Besides, there is RAISEVENT(), it's not perfect, but it's a bit better than just calling container.mousemove(). A bindevent that's configured to not react to direct method calls will react if you instead use RAISEEVENT, for example. And to ActiveX controls this should also look like an event occured and they'd react, too, or any related events also occcr.

Just to demo all this differences:
Code:
Clear
_screen.AddObject("mycontainer1","mycontainer")
_screen.mycontainer1.visible = .t.
@ 10,1 say '' && move to line 10, after the container.

? 'Mousemove method call:'
_screen.mycontainer1.mousemove(0,0,9,9)
? 'RaiseEvent:'
RaiseEvent(_screen.mycontainer1,"MouseMove",0,0,10,10)
? 'Mouse at 0,0 Drag to 1,1 then ',_screen.mycontainer1.height+20,5
Activate Screen

Mouse at 0,0 Drag to 1,1
Mouse at 1,1 Drag to _screen.mycontainer1.height+20,5 pixels


Define Class mycontainer as Container
   Procedure init()
      BindEvent(This,"MouseMove",This,"MouseMoveBindevent",1+2)
      * where 2 means: Do not allow an event to be triggered with a simple method call
   EndProc
   
   Procedure MouseMove()
       LPARAMETERS nButton, nShift, nXCoord, nYCoord
       
       ? "MouseMove", nButton, nShift, nXCoord, nYCoord
   EndProc    

   Procedure MouseMoveBindevent()
       LPARAMETERS nButton, nShift, nXCoord, nYCoord
       
       AEvents(laEvents,0)
       
       ? "MoseMoveBindevent", nButton, nShift, nXCoord, nYCoord, laEvents[3] && see AEVENTS
   EndProc 
EndDefine

For sake of simplicity make the VFP window fullscreen in the main display (matters, if you have multiple displays), then run it. That should be output:
mosueeventss_dqwycr.jpg


1. calling the mousemove event doesn't trigger the MouseMoveBindevent, therefore only the mousemove output is done.
2. Raisevent causes both the mousebindevent and mousemove. Also, notice the 1 at the end of the output of MouseMoveBindevent, that means you can detect this event was caused by VFPs RaiseEvent function.
3. Mouse at...drag to also causes both the bindevent and the mousemove event. Here the last number 0 means it's detected as a system event. The MOUSE command actually causes the system mouse to move and that in turn means it's detected as system event.

In some cases I also get further events happening, also with the coordinates the mouse as previously to putting it to 0,0 but I don't get that reproducible. The two drag operations should at least cause two events at 0,0 and 1,1, the two starting points, but maybe it's a timing issue and too fastly occurring events are sometimes not forwarded or ignored. The final coordinates 95,5 mean the _screen (x,y) coordinates (5,95) and are picked outside the container (if VFP is fullscreen in the main display), so moving the mouse after running this code doesn't obliterate the screen with event output, but you can, of course, move the mouse to the container and will see output from that.

Both raisevent and actually causing the event by the MOUSE command also trigger the actual event. So the bound event, which is configured to not react to direct message calls, reacts, too. You can always also trigger events, even in case there is no such command as the MOUSE command by sending the Windows messages that cause these events, for example, WM_KEYDOWN and WMKEYUP to simulate a keyboard press of a key. There are limitations about which events you can raise in other processes, but within your own windows (forms) it would always be possible to get something like that going, in case you really need it.

When you realize you actually only have display update problems, then the most rigorous thing you can do to cause a complete repaint also is form.Cls(), but it's sensible to only use the least, which is control.setfocus() to the control that should update its own display, followed by control.refresh() and then also the full form.refresh() and form.cls() at the top of it all. You could even also cause the repaint of a rectangle within the form via Windows API:
Just look around a bit more next time, there are so many options you overlooked.

Chriss
 
Chriss,

Thanks for your explanation and comments. Like I already stated the solution to my “problem” was very simple.
I will keep your suggestions in my archive for further reference.

Regards, Gerrit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top