Recent

Author Topic: TGroupBox, positioning of items  (Read 4713 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
TGroupBox, positioning of items
« on: October 26, 2015, 06:12:55 pm »
This subject seems to have a history, and various web and forum items do not seem consistent, possilby reflecting historical positions.

If I create a TGroupBox, then add, say, a checkbox or spinedit, and specify Top=0, then the visual position varies. How can I make Lazarus just position the sub-items where I tell it to?

Most of the discussion I;ve found relates to the Delphi converter. I am creating new code.


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TGroupBox, positioning of items
« Reply #1 on: October 26, 2015, 08:55:16 pm »
If I create a TGroupBox, then add, say, a checkbox or spinedit, and specify Top=0, then the visual position varies. How can I make Lazarus just position the sub-items where I tell it to?

The visual position does not vary, it is always at 0 if that is where you set it.
That may not be the position you want, however, since the client 'top' of a TGroupBox is several pixels below its upper border. This is to allow for the writing of the groupbox Caption, and a small margin, and is widgetset dependent.

If you want to position child controls up against the visible upper borderline of a groupbox you can set the child's Top property to a negative value. On Windows you would need to set the Top to  -10. Other widgetsets and operating systems may differ from 10, but probably not by much. Of course a long Caption might then be partly obscured by your child control.

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: TGroupBox, positioning of items
« Reply #2 on: October 26, 2015, 11:18:00 pm »
That does not seem to correspond with what I see.  Because I have a form with quite a number of controls in a complex layout, I have a routine that positions the controls, rather than doing it through the IDE. Fore example, I have two TGroupBox's. In each of them I position a TLabel and a TSpinEdit, plus other controls, vertically at the same value. The two TGroupBox's display the comtrols in different vertical positions. Now I'm always willing to consider I have made some error in my coding, but I cannot see what causes this different positioning.

Could there be some bug with the offset? In Delphi the vertical position of a control inside a TGroupBox is relative to the actual top of the box.  That is simple to understand and use. Is the offset in Lazarus accessible to programs?

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: TGroupBox, positioning of items
« Reply #3 on: October 27, 2015, 01:15:48 am »
Enbarassingly, I have to confess that I found a coding error that caused some of strange positioning that I described, but not all. (Even after decades of serious programming experience this still happens!) What I have discovered is that if you try to position controls inside a TGroupBox so that the top of a control is <0, then the IDE may refuse to display them, and run-time positioning may not be what you expect. So my solution is to not try and encroach on the vertical offset space in a TGroupBox. On a very control-busy form this forces the form to be bigger than I might otherwise want, but development deadlines are too short to worry about that.

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Re: TGroupBox, positioning of items
« Reply #4 on: October 27, 2015, 09:33:32 am »
Just to note, it's essential to have AutoSize-false when positioing controls in a TGroupBox by cide.

 

TinyPortal © 2005-2018