[SOLVED] Autosize - How to know size before show? lazarus / 31-LCL ---------------------------------------------------------------------- Dibo · 2011-02-17 23:32 Hi, I have problem with autosize. I am reading documentation of this property but can't find solution. I have this situtation (this is only example, in my form is more controls with autosize): Form1.Autosize = True; Label1.AutoSize = True; Label1.Align = alTop; When I change caption in Label1, form width is "fit" to this size. This is ok, but new form width is calculated only when I make it visible. How do I know final form width before show? Regards. ---------------------------------------------------------------------- Blaazen · 2011-02-18 00:27 I made a few experimetns and I have no idea how to do it in convenient way.  Only thing that work for me is this crazy method: Code: [Select]  Form2.Show;   Form2.Close;   Caption:=inttostr(Form2.Width);    //now it has final size  Show and Close is sooooo fast ..... ---------------------------------------------------------------------- Martin_fr · 2011-02-18 01:17 it's somewhere on the wiki. forms autosize only ONCE. To autosize a form a 2nd time, set Form.Autosize to False, and then back to true again. You must do this, each time you need the autosize. --- The reason: under Linux some Windowmanager do interfere with autosize... search the wiki, read the full story there ---------------------------------------------------------------------- Blaazen · 2011-02-18 01:51 http://wiki.lazarus.freepascal.org/Autosize_/_Layout#AutoSize_and_Form s But seems not work for invisible forms at least here on Qt. ---------------------------------------------------------------------- zeljko · 2011-02-18 11:19 I don't use autosize for forms, but again,don't understand what does not work with qt ? afaik, it does not matter if form is visible or not. Open an issue about it and attach example. ---------------------------------------------------------------------- Blaazen · 2011-02-18 11:52 OK. I opened issue http://bugs.freepascal.org/view.php?id=18775. When you say that invisible forms should be resized than it is probably bug. ---------------------------------------------------------------------- Dibo · 2011-02-18 12:56 Quote from: Martin_fr on February 18, 2011, 02:17:18 amit's somewhere on the wiki. forms autosize only ONCE. To autosize a form a 2nd time, set Form.Autosize to False, and then back to true again. You must do this, each time you need the autosize. This doesn't work on linux (GTK). I try read more about this ---------------------------------------------------------------------- Dibo · 2011-02-18 14:57 @Blaazen. Mattias Gaertner post nice trick in your issue. This code solve my problem and return me final form width without showing it: Form1.HandleNeeded; Form1.GetPreferredSize(W,H);