Recent

Author Topic: Form AutoSize and TSringGrid  (Read 9486 times)

mas steindorff

  • Hero Member
  • *****
  • Posts: 560
Form AutoSize and TSringGrid
« on: October 11, 2010, 06:20:10 pm »
I have a TStingGrid on it's own form that I add a line to each time it is shown.  I would like the form to re-size itself to show all of the string grid.  I've tried setting the forms AutoSize to true but that doesn't seem to do anything. 
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

zariq

  • Full Member
  • ***
  • Posts: 109
Re: Form AutoSize and TSringGrid
« Reply #1 on: October 11, 2010, 06:46:00 pm »
the only way the form will resize is if the side of the  stringgrid drops off the edge of the form. If you add a column or row to the stringrrid, then what happens depends on the scrollbars property. Set it to ssautoboth. If you dont want scrollbars on the stringgrid then you have to set the height and width of the stringgrid to show all rows and columns. In the latter case you will end up with scroll bars on the form.

mas steindorff

  • Hero Member
  • *****
  • Posts: 560
Re: Form AutoSize and TSringGrid
« Reply #2 on: October 11, 2010, 07:16:25 pm »
the only way the form will resize is if the side of the  stringgrid drops off the edge of the form. If you add a column or row to the stringrrid, then what happens depends on the scrollbars property. Set it to ssautoboth. If you dont want scrollbars on the stringgrid then you have to set the height and width of the stringgrid to show all rows and columns. In the latter case you will end up with scroll bars on the form.
I've tried both settings for the scrollbars (none and autoboth).  in both cases the form size stays fixed at it's original size (or last set size if I drag it at run time).  I've also tried calling the form's adjustsize and doautosize without success.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

zariq

  • Full Member
  • ***
  • Posts: 109
Re: Form AutoSize and TSringGrid
« Reply #3 on: October 11, 2010, 08:16:23 pm »
Hi.

Sorry if my reply was unclear.

I you want the form and stringgridgrid size to stay fixed but want to add scrollbars to the stringgrid so you can scroll up and down to view all the items then you need to set the stringgrids scrollbars property to the the following

ssvertical : fixed vertical scrollbar
sshorizontal : fixed horizontal scrollbar
ssboth        : fixed both horizontal and vertical scrollbars

These settings will put a scroll bar on the stringgrid whether it needs it or not. I you want it to add and remove the scrollbars automatically when the need arises then then set it to ssautoboth,
ssvertical or sshorizontal.

If you dont want any scroll bars on the stringgrid but want to resize the form then set the stringgrid scrollbars property to ssnone and in the preparecanvas event of the stringgrid  set the result of the stringgrid rowcount property multiplied by the stringgrid rowheights property to the stringgrids height property.

eg.
 stringgrid1.height := stringgrid1.rowcount*stringgrid1.rowheights[any valid row];.

That sould work if all your rows are the same height, if not then you have to take that into consideration.

and obviously you will have to set the forms autosize to true.

Bye.


mas steindorff

  • Hero Member
  • *****
  • Posts: 560
Re: Form AutoSize and TSringGrid
« Reply #4 on: October 12, 2010, 06:19:59 am »
well, I tried your suggestions without any success :'(.  they were basically the same as I had.  I was trying to use the form auto size to avoid having to play with the math of adding the heights of all of the objects. Autosize and stringgrids just doesn't work.  perhaps it something to do with the status bar.

I've resorted to the old grunt way  :'(
(was just trying to learn something new but is may just be too new)
I read there will be a new release soon, I'll retry after It comes out.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Form AutoSize and TSringGrid
« Reply #5 on: October 12, 2010, 08:30:30 am »
Apart from the fact that I don't understand your goal: Do you know TStringGrids method AutoSizeColumn(s)?
Lazarus 1.7 (SVN) FPC 3.0.0

mas steindorff

  • Hero Member
  • *****
  • Posts: 560
Re: Form AutoSize and TSringGrid
« Reply #6 on: October 12, 2010, 04:48:44 pm »
My goal was to show a (small as possible) "score card" form off to the side of the game.  The user can position the form or close it as he wishes.  After each game, a line is added to the score card.  Having never used the auto size, I decided to try it to see if I could avoid doing the math for the form resize as the math changes depending on OS and theme and font.  I suppose I can move some of the other components off the form to make it simpler but it's what I have for now.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

 

TinyPortal © 2005-2018