JvgPageControl上的左对齐Tabsheets Delphi + Vcl样式已启用问题

时间:2014-01-26 17:00:10

标签: delphi vcl-styles pagecontrol

在Windows默认外观上,标签页标题以水平方式显示(从左到右1),启用VCL样式后,它们以垂直方式显示(从下到上[2])。我如何在Delphi XE5上解决这个问题? 细节:我正在使用来自JEDI-VCL 3.58的JvgPageControl组件。

我想创建一个类似DisplayFusion欢迎屏幕的界面[3]。欢迎提出建议!

图片:

enter image description here

提前致谢!

1 个答案:

答案 0 :(得分:2)

TJvgPageControl使用TTabControlStyleHook控件的相同vcl样式钩子(TPageControl),因此您必须创建一个从TTabControlStyleHook继承的新样式钩子并覆盖{{1} } 方法。

检查新样式挂钩的基本实现

DrawTab

然后像这样注册新的样式钩子

type
   TTabControlStyleHookExt = class(TTabControlStyleHook)
   protected
    procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
   end;

   TCustomTabControlClass = class(TCustomTabControl);

{ TTabControlStyleHookExt }

procedure TTabControlStyleHookExt.DrawTab(Canvas: TCanvas; Index: Integer);
var
  R, LayoutR, GlyphR: TRect;
  ImageWidth, ImageHeight, ImageStep : Integer;
  LDrawState: TThemedTab;
  LDetails: TThemedElementDetails;
  ThemeTextColor: TColor;
  FImageIndex: Integer;
begin
  if TabPosition <> tpLeft then
  begin
    inherited ;
    exit;
  end;

  if (Images <> nil) and (Index < Images.Count) then
  begin
    ImageWidth := Images.Width;
    ImageHeight := Images.Height;
    ImageStep := 3;
  end
  else
  begin
    ImageWidth := 0;
    ImageHeight := 0;
    ImageStep := 0;
  end;

  R := TabRect[Index];
  if R.Left < 0 then Exit;

  if Index = TabIndex then
    Dec(R.Left, 2)
  else
    Dec(R.Right, 2);

  Canvas.Font.Assign(TCustomTabControlClass(Control).Font);
  LayoutR := R;

  if Index = TabIndex then
    LDrawState := ttTabItemLeftEdgeSelected
  else if (Index = HotTabIndex) and MouseInControl then
    LDrawState := ttTabItemLeftEdgeHot
  else
    LDrawState := ttTabItemLeftEdgeNormal;

  LDetails := StyleServices.GetElementDetails(LDrawState);
  StyleServices.DrawElement(Canvas.Handle, LDetails, R);

  { Image }
  if Control is TCustomTabControl then
    FImageIndex := TCustomTabControlClass(Control).GetImageIndex(Index)
  else
    FImageIndex := Index;

  if (Images <> nil) and (FImageIndex >= 0) and (FImageIndex < Images.Count) then
  begin
    GlyphR := LayoutR;

    GlyphR.Bottom := GlyphR.Bottom - ImageStep;
    GlyphR.Top := GlyphR.Bottom - ImageHeight;
    LayoutR.Bottom := GlyphR.Top;
    GlyphR.Left := GlyphR.Left + (GlyphR.Right - GlyphR.Left) div 2 - ImageWidth div 2;

    if StyleServices.Available then
      StyleServices.DrawIcon(Canvas.Handle, LDetails, GlyphR, Images.Handle, FImageIndex);
  end;

  { Text }

   if StyleServices.GetElementColor(LDetails, ecTextColor, ThemeTextColor) then
     Canvas.Font.Color := ThemeTextColor;

    //use the top tab style to draw the text
    if Index = TabIndex then
      LDetails := StyleServices.GetElementDetails(ttTabItemSelected)
    else
    if (Index = HotTabIndex) and MouseInControl then
      LDetails := StyleServices.GetElementDetails(ttTabItemHot)
    else
      LDetails := StyleServices.GetElementDetails(ttTabItemNormal);

     DrawControlText(Canvas, LDetails, Tabs[Index], LayoutR, DT_VCENTER or DT_CENTER or DT_SINGLELINE  or DT_NOCLIP);
end;

enter image description here