Solved

Moving objects programmatically within the .INIT() event

Posted on 2012-03-15
2
493 Views
Last Modified: 2012-06-21
I'm trying to keep my FORMs tidy by hiding unused objects and moving others up to fill these spaces.

The particular FORM that I'm having trouble with has a pageframe. Within that there's a series of pages. Within those there's a series of objects, mostly containers.

Within the .INIT event for container A, we decide whether it's needed. If it isn't, then it gets hidden with a
    .VISIBLE = .F.

Let's suppose that container B is just below this. It is needed, so the .VISIBLE property is set as .T.

Then what I'm trying to do is within the .INIT event. The code looks like

FOR EACH loObject1 IN THIS.Objects
      IF .NOT. loObject1.Visible
            FOR EACH loObject2 IN THIS.Objects
                  IF ( loObject2.Top >= loObject1.Top + loObject1.Height )
                        loObject2.Top = loObject2.Top - loObject1.Height
                        ENDIF
                  NEXT
            ENDIF
      NEXT

That all seems to work - tracing it through with DEBUG certainly re-positions container B higher up the window.

But after it's gone through that process, and after it has come out of the page's INIT event, then the object position springs back to its original value.

Any suggestions?
0
Comment
Question by:IainMacb
2 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 400 total points
ID: 37728153
Do you use non-zero Anchor property for Containers? If yes then you have to set it to zero before "shuffling".
0
 
LVL 1

Author Comment

by:IainMacb
ID: 37728747
Brilliant. Key section of code changed to

FOR EACH loObject1 IN THIS.Objects
      IF .NOT. loObject1.Visible
            FOR EACH loObject2 IN THIS.Objects
                  IF ( loObject2.Top >= loObject1.Top + loObject1.Height )
                        llAnchor         = loObject2.Anchor
                        loObject2.Anchor = 0
                        loObject2.Top    = loObject2.Top - loObject1.Height
                        loObject2.Anchor = llAnchor
                        ENDIF
                  NEXT
            ENDIF
      NEXT

Now works perfectly. Many many thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Read our guide on how to survive being on-call.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question