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

Find visible objects inn scrollable mainform

Status
Not open for further replies.

gjbbroekhuis

Programmer
Jun 11, 2013
17
0
0
NL
Hi,

I'm using a scrollable mainform that can contain up to 28 containers, each 240 pixels wide, with a 10 pixel spacing. Total width can be up to around 7000 pixels.
When the form has scrolled to the right or to the left, how can I determine the name of the container that's visible that moment on the left side of my display?
Is there any way to determine by code what's visible (and where) in the shown portion of such a big form?

Regards, Gerrit
 
Why don't you do it the other way around?

So, what am I talking about...

Several years ago (might be a deacde by now :) ) I wrote an app that had to display all trucks on a timescale that could be changed to day, 3-days, 5-days and week and could be scrolled horizontally (days +/- or week +/-) and vertically if there were more trucks in the company than the form configuration could display all at once.
Instead of creating all objects I reduced them to the timescale they were indeed visible. And those by vertically scrolling too. that reduced the amount of instanciated containerobjects extensively.
That way you don't have to check which one is visible. You can select your data based on the shown days and in case the user scrolls up or down, move the already and afterwards still visible containers up and down. Remove those, that are not visible any longer and make the new objects visible in new containers.
And you could still place all vertical members at once and only remove or move them as soon as the main container is scrolled horizontally.


JM2C

ADDED:
BTW, I didn't need a scrollable form for that. All objects where placed in a containerobject.

-Tom
 
Hi,

I have a scrollable form already and adding a scrolleable container holding all containers, labels and more would be quite a challenge, due to the classes creating all these elements.

It seems using the ViewPort parameters work fine when using this in the form.scrolling event. I see no disadvantage using this, besides a slight flickering when scrolling the form. Probably the form gets updated for every scrolled pixel. Adding LockScreen does not help unfortunately. But for this purpose thsi is not a big thing.

I think I will use OBJTOCLIENT in a search function, that will show the right information on my screen. Something to work on later this week.

Regards, Gerrit
 
Just to amplify my answer (and assuming I have understood the question correctly) ...

If you divide the ViewPortLeft by 250 ( = 240 + 10) and round up to the next whole number, that should tell you which container is at the left hand edge of the view port.

For example, if your ViewPortLeft is 700, then the result of the above calculation will be 3, so your third container should be the first one that's completely visible.

You may need to adjust the calculation, for example if you have a gap between the very edge of the form and the first container. But the basic principle is the same.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
For anything directly on the form OBJETOCLIENT() gives the same values as the LEFT, TOP, WIDTH, and HEIGHT properties, but it gives a simple coordinate space for anything if you apply it to controls within your containers and compare against the viewport coordinates.

Regarding when the values change I haven't done experiments (no time), but see the ContinuousScroll property.

Bye, Olaf.


Olaf Doschke Software Engineering
 
Hi Mike,

For each of 7 to 28 days (according to the selected data and dates) I have a container 240 pixels wide plus a 10 pixel spacing. I changed HScrollSmallChange to 250, so every mouseclick on the horizontasl scrollbar will make another day visible, as the viewpoint changes with 250 pixels. Using Scrolled event of the form does the job, with only a minor flickering when scrolling as the only disadvantage.

Regards, Gerrit
 
Gerrit, good to hear that you have a solution.

Regarding the flickering, have you tried setting the form's LockScreen to .T. at the start of the scrool, and setting it back to .F. at the end. I'm not sure if that would work, but it would be worth a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The reason for flickering can be manifold, you might even get better results with graphic card hardware acceleration turned off. VFP does not use DirectX, Direct3d or even Direct2d, it's only GDI+. But you're not setting containers invisible when they are outside the viewport and visible when they scroll in, or do you? If it's that, then don't switch the visibility of the containers.

Do you want to prevent focus going off the viewport into a control not seen? Why not do the inverse? In Gotfocus you can check whether objtoclient(this,1) is larger than thisform.viewporttop+thisform.viewportheight and so needs to be scrolled up to become visible. Or whether the focused control is above the visible portion and needs to scroll down, etc.

It's even easier if you just make it a property of the containers, which viewport positioning will center it, that can be computed once at init or in the simplest case when the container is directly on the form, it's its own (left,top) plus a margin. You can't set the viewport properties directly, but you have thisform.setviewport(left,top) and so have a way to scroll to positions as you like instead of using DoScroll for that or reacting to Scrolled events. And you won't need to react to Scrolled events, but you can of course also setfocus automatically. So many things are possible in both ways: Scrolling causes focus change, focus change causes scrolling.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Mike, Olaf,

The only flickering occurs in the buttons I want to keep in place above the containers when scrolling the mainform. It’s not a big issue, as the containers move and scroll smoothly, and I will continue with this after Easter weekend.

Happy Easter!

Regard, Gerrit
 
Okay, you could try to reposition the buttons relative to the viewport coordinates in form.paint(), too, not just form.scrolled().

But I fear this happens too late, too. To be informed before the scrolled form is painted, that would require binding to windows messages via BINDEVENT(), you likely get what you want when you intercept WM_PAINT and position buttons, then continue with the message processing. The VFP samples show how to do that, specifically which API functions you need to declare and call to chain your event code into the event chain just in time and still continue and not suppress the native event processing.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top