Two solutions:
By default the width of a tab is determined by the length of the caption. By using the TabWidth property it can be adjusted to any width. The trick here is to adjust the TabWidth such that it stretches over half of the ClientWidth of the parent - this way the PageControl can accomodate only two tabs per row and then must wrap the next tabs into the next row (provided that the Multiline options is active). When you put this code into the OnResize event handler of the PageControl's parent, this layout of two tabs per row will be independent of the pagecontrol's Width:
procedure TForm1.FormResize(Sender: TObject); // For PageControl directly on the form
begin
PageControl1.TabWidth := (ClientWidth - 10) div 2; // 10 subtracted for some unknown margins
end;
A disadvantage is that multi-lined Pagecontrol are not supported in all widgetsets...
Another solution combines some controls to a "faked" pagecontrol - well, you will have to accept something which does not look exactly like a TPageControl, but it serves the same purpose:
- Drop a panel on the form (or the parent which will contain the pagecontrol). Select Align = alTop.
- Drop four speedbuttons on this panel, place them anywhere
- Go to property "ChildSizing" of the panel, set its "Layout" to "cclLeftToRightThenTopToBottom" and "ControlsPerLine" to 2 - now the speedbuttons are arranged nicely in two rows.
- Drop a TNotebook on the form (or the parent of the "faked" pagecontrol). Set Align = alClient. Like a TPageControl, a TNotebook can have several pages, but there are no tabs. Therefore, you need the Speedbuttons - they serve as tabs...
- Right-click on the TNotebook and add four pages - you will not see the pages in the designer form, but in the object tree. For adding controls to each page, select it first in the object tree.
- Now return to the speedbuttons and specifiy in the
"Tab" "Tag" property the index of the notebook page associated with the button. - Write the following handler and assign it to each speedbutton's OnClick event:
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Notebook1.PageIndex := (Sender as TSpeedButton).Tag;
end;
To give you idea what this looks like I am attaching a simple dummy project with both solutions.