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

Scrolling a form programmatically

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I have a form with a vertical scrollbar. I want to be able to scroll the form programmatically, but can't figure out how to do it.

To elaborate ...

I am adding objects to a form by drag and drop. As each object is dropped, I position it below the previous object, which might place it below the visible area of the form. In order to see it, the user can use the vertical scroll bar. That's all working fine.

What I now want to do is to enable the user to see the new object as soon as it is in position, without having to manually scroll. In other words, I want to programmatically scroll the form downward by an amount equal to the height of the new object.

This is what I have done so far:

Code:
WITH thisform
  .setViewPort(.ViewPortLeft, .ViewPortTop + 10)
ENDWITH

This correctly scrolls the form by 10 pixels, but the newly added object is not visible. I just see a blank space where the object should be. However, if I then use the scrollbar to scroll, even by just a single pixel, the new object becomes visible.

I don't understand why this is happening this way, and what I am doing wrong. If anyone come help me out, I'd appreciate it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
could you fire the 'scrolled' event - see if the default behaviour did anything?

Regards

Griff
Keep [Smile]ing
 
A couple ideas I was tossing around:

Which order are you doing it? Adding the object first then setting the viewport or vice-versa?
Does refreshing the newly added object right after adding make a difference?
How about setting .visible = .T. (maybe again) right after setting the viewport?



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Mike

I have a textbox class modified for use in data entry forms with the following code in the .When() event.
Code:
[COLOR=blue]THISFORM.SetViewPort(0,THIS.Top - 20)[/color]
As the user tabs or clicks their way through the controls, the textbox or any other control with the same code is always at the top of the screen.

Maybe you could programatically set focus to the newly added control and immediately set focus elsewhere in required.

This might give you what you are seeking.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Chris, Dave, Martin,

Thanks for all your replies. I've been experimenting with your suggestions.

Dave:

I tried all your ideas, but none of them helped. I also tried calling the form's Draw method (rather than a Refresh), but no luck.

Chris:

I think your suggestion could be useful in other parts of the application, but with the present issue the object being added is a container, and doesn't get focus (nor do any of its contained controls, which are images and labels). I tried setting focus to it programmatically, but that didn't make any difference.

Martin:

Your idea of calling the Scrolled event does seem to make a difference, although it doesn't give me exactly what I need. However, if I move the viewport twice, calling Scrolled each time, it gets me close to what I want (although I don't understand why).

At the moment, this is all in the prototype stage, so I won't spend too much longer on it. But if I do find a solution, I'll let you all know.

Thanks again.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Just to wind up this topic.

I've finally solved the problem by adding a shape to the form. When I add a new object to the form, I increase the size of the shape. Each new object sits inside the shape, so the shape completely encompasses the objects.

Having done that, I find that I can set the viewport programmatically, and the form behaves as I expect.

I don't really understand why this is working the way it does. But at least the problem appears to be solved .. for now.

Thanks again for all those who replied.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top