views:

511

answers:

2

Has anybody experience with Delphi 2009's TCategoryPanelGroup component and specifically with dynamically adding buttons to category panels?

I can't get it to work properly. Either the buttons do not appear or the alignment is screwed up. Basic outline of what I want to do:

procedure AddButton (const Caption, Group : String);
const 
  ButtonSize = 55;
  Border = 10;
var
  CategoryPanel : TCategoryPanel;
  Button : TButton;       
begin
  CategoryPanel := FindCategoryPanel (CategoryPanelGroup, Group);
  CategoryPanel.Height := CategoryPanel.Height + ButtonSize + Border;
  Button := TButton.Create (CategoryPanel);
  Button.Parent := CategoryPanel;
  Button.Width := ButtonSize;
  Button.Height := ButtonSize;
  Button.Left := 27;
  Button.Top := CategoryPanel.ClientHeight - Border - ButtonSize;
end;

Any hints?

A: 

What is exactly the problem? The buttons are shown exactly at the position required.

Are you sure you want square buttons without text?

Using :

Button.Left := 0;
Button.Width := CategoryPanel.ClientWidth - 2;

Makes them the exact width as the panel minus an offset of a pixel.

Using:

Button.Width := CategoryPanel.ClientWidth; Button.Left := -1;

Creates the biggest width. It There is a 1 pixel offset.

[[I'm using 2010 to be fair]].

Gamecat
And there is also a 1 pixel offset in the height.
Gamecat
In the actual application the buttons are subclasses of TButton and they contain images.
Smasher
For the exact problem: the buttons do not appear at the correct location. They either do not appear at all or they are on top of each other with only a small offset.
Smasher
Ok, I tried with normal TButton on 2010 and it looks ok (with regard of the 1 pixel offset). Can you dynamically create the button on a normal TPanel?
Gamecat
Can't try it now (no access to Delphi)...I will update on monday. Thanks for your help.
Smasher
Hi, got it to work...not sure about the reason why the above did not work for me.
Smasher
A: 

Problem was the way I specified the top coordinates.

I changed it to something like

ButtonCount := CategoryPanel.ComponentCount - 2;
Button.Top := Border + ButtonCount * (ButtonSize + Border);
CategoryPanel.ClientHeight := Border + (ButtonCount+1) * (ButtonSize + Border);

and it works.

Don't know exactly what caused the problem.

Smasher