Results 1 to 5 of 5

Thread: Creating a theoretical Z function

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Illinois, USA
    Posts
    7

    Post

    Hey everyone, I need some help. I have an index of standard VB image controls on a form. The amount of indexes of the control is unknown, as they are added dynamically at different counts at different times.

    I need help with creating a function that I can call to create a sort of pretend z-level. See, each image will have a different left and top value. I need to position the controls so, for example, the one with the farthest TOP value will be on top, and the one shortest with be on the bottom.

    I understand how to use the .ZOrder method, but I'm not sure how I can use it to create this effect. I hope I explained this right, if not ask me and I'll try to be more detailed.

    Thanks greatly to anyone who replies.

    - Evan Sims

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Trying to create a 3D application?

    ------------------
    DiGiTaIErRoR

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I think this does what you want.
    Code:
        Dim MyCollection As New Collection ' Create a collection to hold Images sorted by Top
        Dim intIndex As Integer
        Dim intIndex2 As Integer
        Dim bAdded As Boolean
        
        ' Examine all the controls on the form
        For intIndex = 0 To Me.Controls.Count - 1
            If TypeOf Me.Controls(intIndex) Is Image Then
                ' It's an Image so add it to the collection
                If MyCollection.Count > 0 Then
                    ' There are items in the collection, so compare their Top
                    ' property to the Top property of the Image to be added
                    For intIndex2 = 1 To MyCollection.Count
                        bAdded = False
                        If Me.Controls(intIndex).Top > MyCollection.Item(intIndex2).Top Then
                            ' It's greater so add the new Image before the one in the
                            ' collection we are comparing it to. The format of the Add statement
                            ' is "CollectionName, IndexString, Before"
                            MyCollection.Add Me.Controls(intIndex), Str(Me.Controls(intIndex).Top), intIndex2
                            bAdded = True
                            Exit For
                        End If
                    Next intIndex2
                    If Not bAdded Then
                        MyCollection.Add Me.Controls(intIndex), Str(Me.Controls(intIndex).Top)
                    End If
                Else
                    ' It's the first item in the collection, so just add it
                    MyCollection.Add Me.Controls(intIndex), Str(Me.Controls(intIndex).Top)
                End If
            End If
        Next intIndex
    
        For intIndex = 1 To MyCollection.Count
            MyCollection.Item(intIndex).ZOrder
        Next
    ------------------
    Marty

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Illinois, USA
    Posts
    7

    Post

    Hi there. I had to change the line:

    Code:
    If Form1.Controls(intIndex).Top > MyCollection.Item(intIndex2).Top Then
    to...

    Code:
    If Form1.Controls(intIndex).Top < MyCollection.Item(intIndex2).Top Then
    to get the effect I needed, but it works perfectly now. Thank you soooo much, you really saved my butt!

    P.S. DiGiTaIErRoR-- Actually, it's a 2D-based map designer for a game I play, which required a few seeminly 3D-looking effects to come off all right.

    [This message has been edited by Okaria Dragon (edited 12-12-1999).]

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Your welcome. BTW you should probably check to see what happens if two of your images have exactly the same top. Do you need to change the comparison to <= ?

    ------------------
    Marty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width