问题
I'm new to Delphi (again - I used Delphi back in 1994). I now have Delphi 2009 Pro.
Coming from Java, I find the object inheritance very obscure.
My users want tabbed pages with the tabs on the left. But, the TPageControl doesn't allow the tab label direction or orientation to be changed. They want the words on the tabs to read top to bottom with the letters rotated so they are in a "normal" orientation. With the tabs on the left the labels read from the bottom up with the letters rotated 90 deg. to the left and there is a tendency to tilt your head to the left to read the tabs. I found several enhancements to the standard TPageControl VCL that add images, text and color changes for hover and active, but nothing that allows the manipulation of font direction or orientation on the tabs.
Page Control Tabls should look something like:
P
a
g
e
1
P
a
g
e
2
P
a
g
e
3
And so on...
回答1:
1.) set the TPageControl properties:
TabPosition := tpLeft;
OwnerDraw := True;
TabWidth := 180; //set to any adequate value because
// TPageControl doesn't have a measure event handler
2.) use the following OnDrawTab code:
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, start and enjoy !
回答2:
Not so much a DIY answer but also wanted to point out the Delphi is a component based development platform and there are several third party VCL controls that offer some very flexible options in rendering and themeing controls.
Ones I've used myself and would recommend:
- Raize Controls.
- JVCL Contains a boat loads of controls and is open source (MPL License).
HTH and good luck
回答3:
As X-Ray said: You need to owner draw the tabs. It's not really that difficult, I have done that before, but I haven't got any code ready to post. You will need to get the tab's canvas and use the TextOut method.
来源:https://stackoverflow.com/questions/769285/how-can-i-change-the-orientation-of-the-label-on-a-tpagecontrol