delphi - 如何更改 TPageControl 上标签的方向?

标签 delphi delphi-2009 tabcontrol orientation tpagecontrol

我是 Delphi 新手(再次强调 - 我早在 1994 年就使用过 Delphi)。我现在有 Delphi 2009 Pro。

来自Java,我发现对象继承非常晦涩难懂。

我的用户想要选项卡位于左侧的选项卡式页面。但是,TPageControl 不允许更改选项卡标签方向或方向。他们希望标签上的文字从上到下阅读,字母旋转,这样它们就处于“正常”方向。标签位于左侧,标签从下往上读取,字母旋转 90 度。向左倾斜,并且倾向于将头向左倾斜以阅读标签。我发现了标准 TPageControl VCL 的一些增强功能,为悬停和事件添加了图像、文本和颜色更改,但没有任何功能允许在选项卡上操纵字体方向或方向。

页面控制选项卡应类似于:

P
一个

电子
1

P
一个

电子
2

P
一个

电子
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.) 编译,start and enjoy !

关于delphi - 如何更改 TPageControl 上标签的方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/769285/

相关文章:

delphi - 在 Delphi 2009 中如何按字母顺序按键列出 TDictionary?

Delphi - X个组件后的TScrollBox问题

regex - Delphi VCL提供正则表达式库吗?

wpf - 无边框的 TabControl wpf (XP)

multithreading - 日志记录和同步

delphi - 在delphi中存储之前检查图像大小

c# - TabControl 闪烁

WPF 多行 TabControl 无需重新排列行

c++ - hell 图书馆(又名 DLL hell )

delphi - 绕过 Delphi 7 中的 OutputDebugString?