Recent

Author Topic: GroupBox question - Component Z order - I need a little help/advice.  (Read 6196 times)

Yukiko

  • Jr. Member
  • **
  • Posts: 55
I am not "new" to Lazarus and Pascal but I am trying to make a program I have wrote some time ago a little nicer looking. Parts of the interface have controls which probably should be grouped together for esthetics if not practicality from a UI standpoint. This program was written in my early days with Lazarus so I was not very adventurous with the design phase. As such I never used TGroupBox.

Here's my problem: I add an empty GroupBox to a tab on my form and move existing components on to it by selecting them and dragging them onto it. Then I set the Z-order of the GroupBox by sending it to the back so as to make my newly added components visible. This works for all of the components except the labels. They are not visible. I can select a label if I click on the empty space where is should be displayed but nothing I do, ie. setting its Z-order to front etc., seems to make it visible. Since these are just labels I can delete the old ones and recreate new ones on the GroupBox but then I do not get the alignment lines when trying to align the labels with the other components in the box.

I have "wised up" and now and place the group box first before adding components. That I assume is the "preferred" way of doing it. Unfortunately that does not help me with the older parts of the interface for which I would like to have in a group box.

Does anyone have any advice that can help me here?

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #1 on: October 07, 2018, 12:35:36 pm »
This works for all of the components except the labels.

Maybe you should use TStaticText, which can be found in the Additional tab.

Yukiko

  • Jr. Member
  • **
  • Posts: 55
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #2 on: October 07, 2018, 12:42:53 pm »
I will give that a try. Thank you Handoko. I'll let you know if it works for having the "alignment" lines appear as they should.
« Last Edit: October 07, 2018, 12:47:37 pm by Yukiko »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #3 on: October 07, 2018, 12:45:21 pm »
I add an empty GroupBox to a tab on my form and move existing components on to it by selecting them and dragging them onto it. Then I set the Z-order of the GroupBox by sending it to the back so as to make my newly added components visible.
If I understand correctly you drag the controls in the *Form Designer* into the GroupBox? This does not work, the controls do not become children of the Groupbox this way. You can see this when you drag the GroupBox to another place - do the controls follow? If not I am right and you should continue reading.

There are two ways (maybe more) how to bring the controls into the GroupBox:
  • Right-click on the control to be moved into the GroupBox. In the context menu there is a "Change Parent". Select the Groupbox in the list and click OK.
  • Select the node of the control in the ObjectTree above the Object Inspector and drag it immediately below the Groupbox node - there is an insertion line when the location is correct.
In both cases, it may happen that the control is not visible any more. This is because its coordinates (left, top) are not changed but are considered to be relative to the GroupBox. Thus, if the control was located at 0, 400, and the groupbox is only 200 pixels high the control will be beyond the lower end of the groupbox. With the control selected (or select its node in the Object Tree), set its property "Top" to some value within the GroupBox (0 is always correct) and then drag it to its final location. The same, of course, with "Left".

If you now drag the Groupbox to another location, the control will follow.
« Last Edit: October 07, 2018, 12:48:11 pm by wp »

Yukiko

  • Jr. Member
  • **
  • Posts: 55
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #4 on: October 07, 2018, 12:57:16 pm »
@Handoko - With static text I still do not get the form alkignment lines.

Thanks wp. I will give that one a go. I keep forgetting the "parent -> child relationship" of components. I bet that is the problem.

In both cases, it may happen that the control is not visible any more. This is because its coordinates (left, top) are not changed but are considered to be relative to the GroupBox. Thus, if the control was located at 0, 400, and the groupbox is only 200 pixels high the control will be beyond the lower end of the groupbox. With the control selected (or select its node in the Object Tree), set its property "Top" to some value within the GroupBox (0 is always correct) and then drag it to its final location. The same, of course, with "Left".

Will this be the case even if I resize the GroupBox to a size that would encompass the components prior to changing their parentage?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #5 on: October 07, 2018, 01:37:29 pm »
Will this be the case even if I resize the GroupBox to a size that would encompass the components prior to changing their parentage?

It may be: depends on the original position of the control. Remember that the position is relative to the Parent, so if you have a control whose actual position would cause it to lie outside the group box boundaries, it will *not* be shown. But, as said before, that's easily corrected by changing that position in the object inspector.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #6 on: October 07, 2018, 03:38:14 pm »
Will this be the case even if I resize the GroupBox to a size that would encompass the components prior to changing their parentage?

It may be: depends on the original position of the control. Remember that the position is relative to the Parent, so if you have a control whose actual position would cause it to lie outside the group box boundaries, it will *not* be shown. But, as said before, that's easily corrected by changing that position in the object inspector.
Yes, the position is always relative to the parent. Having Top = 400 means that the control is 400 px below the top edge of the clientarea of its parent. When the control has a 600-px high form as parent then the control is visible. But when the parent is changed to a 200-px high GroupBox the control vanishes beyond the lower edge of the GroupBox. Of course, you can increase the height of the GroupBox to, say, 500 pixels, then the control will come in again. There's one exception: if the control is anchored to the bottom of its parent (akBottom included in Anchors) then the control will move along with the bottom edge of the groupbox while its size in changed. Quite disappointing sometimes... But now that you know about the background it's only half the pain.

BTW, just tested Delphi for this aspect: It is similar - the coordinates are assumed to be relative to the current parent when the parent changes, but the control cannot move out of the parent. Therefore the control is always visible - maybe better than in Lazarus. Feel free to post a feature request in the bugtracker.

Yukiko

  • Jr. Member
  • **
  • Posts: 55
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #7 on: October 08, 2018, 01:46:10 am »
I tried your suggestion. I selected all of the items I wanted to add to the control and right-clicked and changed their parent to the GroupBox. I did lose sight of them and resizing the GroupBox did not bring them back into sight. I haven't messed with their anchor property. So I do not know if that is set to bottom by default. I will check that out before I try again. Maybe selecting one component at a time will work better.

However, in trying to undo the parent change by pressing <ctrl>-z a few times Lazarus IDE kicked an exception. I chose to abort. I had not saved my changes so basically except for a few things I have my un-GroupBox'ed components back. I do not know why Lazarus had the exception error. At first I suspected Lazarus had reached the bottom of the "changes" queue and tried to access an invalid area of memory but in retrospect I am pretty sure I had not <ctrl>-z'ed past the last changes made during that session. When I get around to it I will try to replicate the error and get as much of the details as I can.

Thank you again for your help.

Yukiko

  • Jr. Member
  • **
  • Posts: 55
Re: GroupBox question - Component Z order - I need a little help/advice.
« Reply #8 on: October 08, 2018, 07:01:06 am »
Changing the parent to the GroupBox worked this time. I selected each component individually though rather than selecting multiple components.

Thanks for the help.

 

TinyPortal © 2005-2018