views:

64

answers:

2

I have Jordan Russel's Toolbar2000 toolbars that I create at runtime with an embedded TFrame and dock on the application main form. This frame has an embedded pane that in turn contains other panels and various controls. So the structure is:

TTBDock
  TTBToolbar
    TFrame     (align=alNone, Autosize=true)
      TPanel 1     (align=alNone, Autosize=true)
        TPanel 2     (align=alTop ,Autosize = false)
        TPanel 3     (align=alTop ,Autosize = false)
        TPanel 4     (align=alTop , Autosize = false)

The idea is that panels 2, 3, 4 have their heights sized explicitly and the frame (and hence the toolbar) then resizes automatically to accommodate the new size.

It works fine except that the size of the toolbar is wrong the first time the toolbar is shown docked on the application main form. If I force a resize of the toolbar at that point (e.g. by explicitly resizing the TPanel heights again from a mouse click) it comes right. I've tried calling the routine to set the size twice, calling Update, Application.ProcessMessages, ReAlign - nothing seems to work except letting the main form paint and then performing the resize manually again.

If I break at the end of the resize routine and inspect the panel size and frame size, they are correct, but the toolbar size is not, so the first time it shows, the frame is partially shown in a wrong-sized toolbar. It comes right after another call to the sizing routine, but only after the main form has painted itself.

I could kludge up something nasty like explicitly resizing the panels after a timer expires but I'd rather solve the problem at it's source.

Any ideas as to why this might be happening (or not happening)?

+1  A: 

Well, this is not solving the problem at its source but could be a quick fix. Floating the bar once before your form is shown would force it to calculate all control alignment and docking it would force the dock to do the same. Like this:

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Insert frame to toolbar, etc..

  TBToolbar.Floating := True;
  TBToolbar.CurrentDock := TBDock;
Sertac Akyuz
+1  A: 

After much gnashing of teeth, I solved this. The problem resulted from the fact that the Font properties of a control and of a Control's Canvas do not become aligned straight away when one assigns to Control.Font.Height. Part of the code that calculated the height of the panels within the frame used the font height after I had assigned to it. I needed to add:

RequiredValueFontHeight   := blah blah..  ;
FFrame.ALabel.Font.Height := RequiredValueFontHeight ;
FFrame.ALabel.Canvas.Font := FFrame.ALabel.Font ;    //  I needed to add this line

Panel.Height              := RequiredValueFontHeight + Panel.Padding.Top + Panel.Padding.Bottom ; 

Thanks for your interest and help anyway.

(answers and comments voted up because.. well, because I'm a nice guy.)

IMHO you should accept your own answer as my post involved a workaround, not a solution. :)
Sertac Akyuz