Dynamic hierarchy

Post

Posted
Rating:
#1 (In Topic #720)
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
I am wondering if there is any way to change the hierarchy of controls in code. The only way I know how is to generate the objects in code in the order you want them to be placed. This is annoying when you would want a control created from within the IDE to be above a control generated from within the program (i.e. the HUD elements in my new game Bring Them On). I could just generate the labels in code, but that does not seem like the optimum solution.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

Technopeasant said

I am wondering if there is any way to change the hierarchy of controls in code. The only way I know how is to generate the objects in code in the order you want them to be placed. This is annoying when you would want a control created from within the IDE to be above a control generated from within the program (i.e. the HUD elements in my new game Bring Them On). I could just generate the labels in code, but that does not seem like the optimum solution.

MyControlName.Raise() will bring it to the top. .Lower() to the bottom for your base objects
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
You can also alter the order in the IDE. Below, I have reversed the order of 3 Buttons.

<IMG src="https://www.cogier.com/gambas/Heirarchy.png"> </IMG>
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’
 I knew there had to be something obvious like that…

Thanks Bruce!

Would be kinda nice to be able to re-order controls in relation to each other and not just the parent, but it does the job.

EDIT: I am now curious about the Hide method. How is it different than changing the visibility?
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
To re-order the controls you will need to have them in a container - A Panel is well suited to this.
I use something similar to set tool buttons in a horizontal panel - This example is set for a vertical sequence.
{As per your example}
If you want to centre them in the panel, you can use

Code (gambas)

  1. Ctrl.X = (InPanel/2) - (InW/2)

Because you are using the 'For Each' in the subroutine, it will use the sequence set in the hierarchy to process.

Code (gambas)

  1. Private Sub SetButtonSequence(InH As Integer, InW As Integer, ByRef InPanel As Panel)
  2. Dim Ctrl As Control
  3. Dim Buffer As Integer = 5
  4. Dim TmpPos As Integer = Buffer
  5.  
  6. For Each Ctrl In InPanel.Children
  7.   If Ctrl Is Button Then
  8.     Ctrl.Height = InH
  9.     Ctrl.Width = InW
  10.     Ctrl.X = Buffer
  11.     Ctrl.Y = TmpPos
  12.     TmpPos += (InH + Buffer)
  13.   Endif
  14. Next      
  15.  

Cheers - Quin.
I code therefore I am
Online now: No Back to the top
1 guest and 0 members have just viewed this.