Dynamic hierarchy
- Technopeasant
- Posts: 140
- Joined: Saturday 13th July 2019 6:50pm
- Location: Stony Plain, Alberta, Canada
- Contact:
Dynamic hierarchy
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.
- BruceSteers
- Posts: 1523
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Dynamic hierarchy
MyControlName.Raise() will bring it to the top. .Lower() to the bottom for your base objectsTechnopeasant wrote: ↑Sunday 8th August 2021 12:07am 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.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1118
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Dynamic hierarchy
You can also alter the order in the IDE. Below, I have reversed the order of 3 Buttons.
- Technopeasant
- Posts: 140
- Joined: Saturday 13th July 2019 6:50pm
- Location: Stony Plain, Alberta, Canada
- Contact:
Re: Dynamic hierarchy
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?
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?
- Quincunxian
- Posts: 171
- Joined: Sunday 25th June 2017 12:14am
- Location: Western Australia
Re: Dynamic hierarchy
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
Because you are using the 'For Each' in the subroutine, it will use the sequence set in the hierarchy to process.
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
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.
Private Sub SetButtonSequence(InH As Integer, InW As Integer, ByRef InPanel As Panel)
Dim Ctrl As Control
Dim Buffer As Integer = 5
Dim TmpPos As Integer = Buffer
For Each Ctrl In InPanel.Children
If Ctrl Is Button Then
Ctrl.Height = InH
Ctrl.Width = InW
Ctrl.X = Buffer
Ctrl.Y = TmpPos
TmpPos += (InH + Buffer)
Endif
Next
Cheers - Quin.
I code therefore I am
I code therefore I am