How to change label orientation on TPageControl?

I am new to Delphi (again - I used Delphi back in 1994). I now have Delphi 2009 Pro.

From Java, I find that object inheritance is very obscure.

My users want to have tabs with tabs on the left. But TPageControl does not allow you to change the direction or orientation of the tab stop. They want the words on the tabs to be read from top to bottom, while the letters rotate so that they are in the "normal" orientation. With tabs on the left, labels are read from bottom to top with letters rotated 90 degrees. left, and there is a tendency to tilt your head to the left to read tabs. I found several improvements for the standard TPageControl VCL, which adds images, text and color changes for hovering and activity, but nothing that allows you to manipulate the direction or orientation of the font on the tabs.

The page controls should look something like this:

P

g
e
1

P

g
e
2

P



3

...

+3
3

1.) TPageControl:

TabPosition := tpLeft;
OwnerDraw := True;
TabWidth := 180;    //set to any adequate value because
                    // TPageControl doesn't have a measure event handler 

2.) OnDrawTab:

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  I: Integer;
  PageControl: TPageControl;
  TextFormat: TTextFormat;
  Text: string;
  TextRect: TRect;
begin
  PageControl := Control as TPageControl;

  Text := PageControl.Pages[TabIndex].Caption;

  for I := Length(Text) - 1 downto 1 do
  begin
    Text := Copy(Text, 1, I) + sLineBreak + Copy(Text, I+1, MaxInt);
  end;

  TextRect := Rect;
  TextRect.Left := TextRect.Left + 5;
  TextRect.Top := TextRect.Top + 3;

  TextFormat := [tfCenter];

  PageControl.Canvas.TextRect(
    TextRect,
    Text,
    TextFormat
    );
end;

3.) compile, !

+8

DIY, , Delphi - , VCL- , .

:

HTH

+1

As X-Ray said: the owner needs to draw tabs. Actually it’s not so difficult, I did it before, but I don’t have any code ready for publication. You will need to get the tab canvas and use the TextOut method.

0
source

Source: https://habr.com/ru/post/1706749/


All Articles