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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to scroll a scrollable form with mousewheel

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
AU
I have a scrollable form, which scrolls fine with the scrollbar and also with mousewheel - when the mouse is over the form.
However, any containers on the form do not seem to be able to pass-though the mousewheel event to the form in the same behaviour as if you had the mouse directly over the form.
I tried BindEvents in the container:

Bindevent(This,"MouseWheel",Thisform,"MouseWheel")

But this just passed the direction of the mouse wheel to the MouseWheel event/method, not the actual movement required.


Alastair
 
But this just passed the direction of the mouse wheel to the MouseWheel event/method, not the actual movement required.

But doesn't the nDirection parameter also tell you the "actual movement"?

If I've understood it right, the sign of the parameter tells you whether you are moving forward or backward (or up or down). The absolute value of the parameter tells you by how much you are scrolling.

Is that what you want?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I can see the parameter nDirection react to the mouse wheel.
But what it is not doing is passing through the scroll movement to the form's scroll behaviour itself.
I have used the nDirection parameter before and moved containers up/down, but this just moves the container, not trigger the scroll event.
With a grid there is "DoScroll" event, but nothing for the form.

Alastair



 
I see what you mean, in this repro the form doesn't scroll when you MouseWheel hovering the container area (intentionally left with a visible black border).
While it's nice to have containers to organize form parts and anchoring without the container themselves being apparent by borderlines or having scrollbars themselves.

Code:
o = CreateObject("scrollableform")
o.AddObject("text1","textbox")
o.AddObject("container1","container")
o.text1.Top = 800
o.container1.visible = .t.
o.text1.Visible = .t.
o.Show()

Define Class scrollableform as Form
   Scrollbars = 3 &6 has to be >0 already at instanciation
EndDefine

What you do have for programmatic form scrolling is making viewport settings via Form.SetViewPort(). You can't set read-only properties about the viewport, but you can set them through this method. I don't know why VFP is inconsistent here, you can set form.top/left/width/height as the single properties they are and not need to use Form.Move() for that. That might have to do with the inheritance of Windows (OS) WinForms behavior about scrollbars, but even if, the Form properties could be bound to the raise the appropriate Move calls, and the Viewport properties could do the same.

Anyway, you have SetViewPort at least. I tried with BindEvents(), too, this makes the call, you can try some of the options the last nFlag parameter offers to call event before delegate, doesn't matter, it all fails to cause the form to scroll.

It has to do with that being a more low-level OS event, there is a windows message WM_MOUSEWHEEL and BindeEents() can also be used to bind to such Windows messages in VFP9 (as an extension of VFP8s BindEvent() capabilities).

Bye, Olaf.

Olaf Doschke Software Engineering
 
I think the form even gets the event first and redirects it to the container. I found a solution in letting the container set itself invisible for the moment of scrolling:

Code:
o = CreateObject("scrollableform")
o.AddObject("text1","textbox")
o.AddObject("container1","scrollformcontainer")
o.text1.Top = 800
o.container1.visible = .t.
o.text1.Visible = .t.
o.Show()

Define Class scrollableform as Form
   Scrollbars = 3
EndDefine

Define Class scrollformcontainer as container
 
    Procedure MouseWheel()
        LPARAMETERS nDirection, nShift, nXCoord, nYCoord

        Thisform.LockScreen = .T.
        This.Visible = .F.
        RaiseEvent(Thisform,"MouseWheel",nDirection, nShift, nXCoord, nYCoord)
        Doevents Force
        This.Visible = .T.
        Thisform.LockScreen = .F.
    EndProc 
EndDefine

So you better have used your own container class or need to pull off adding this to the MouseWheel event of any container, which should pass the scrolling on to the form.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Olaf,

Tested and working. Yes everything is classed. Thanks!

Edit: only scrolls when you spin the wheel multiple times. I will test more and report back

Alastair
 
Yes, I see, but SendMessage of WM_MOUSEWHEEL sent to the form ends up where it came from. So finally calling SetViewPort might be the best.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top