PDA

Click to See Complete Forum and Search --> : Creating a theoretical Z function


Okaria Dragon
Dec 11th, 1999, 10:08 AM
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

DiGiTaIErRoR
Dec 11th, 1999, 06:07 PM
Trying to create a 3D application?

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

MartinLiss
Dec 12th, 1999, 01:03 AM
I think this does what you want. 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

Okaria Dragon
Dec 12th, 1999, 03:37 AM
Hi there. I had to change the line:

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

to...

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).]

MartinLiss
Dec 12th, 1999, 05:55 AM
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