3

如果您在 JVCL 的 JvDocking 示例代码中运行 AdvanceDemo,选择 VSNetStyle,您可以将第二个表单拖到主表单上;将显示带有第二个表单标题的选项卡。如果您随后将另一个表单拖到主表单的同一侧,将创建另一个选项卡。这两个选项卡将重叠:

重叠选项卡的屏幕截图

有没有办法控制这两个选项卡重叠的程度?我希望标签足够分开,以便用户可以阅读两个标签上的文本。

谢谢,一如既往 - Al C.

4

1 回答 1

5

正如 ain 评论的那样,我也认为这是一个错误。更准确地说,是 TJvDockVSChannel.Paint 中的一个错误,它绘制了选项卡(在内部,这些选项卡称为blocks)。这样的块有一个受保护的属性InactiveBlockWidth,其名称暗示控制其宽度。该属性适用于选项卡本身,但标题在 TJvDockVSChannel.Paint 中再次移动了相同的数量,在我看来这是问题所在。

您可以通过分配 DockServer 的 OnFinishSetDockPanelSize 事件进行如下实验:

type
  TJvDockVSBlockAccess = class(TJvDockVSBlock);

procedure TMainForm.lbDockServer1FinishSetDockPanelSize(
  DockPanel: TJvDockPanel);
var
  Channel: TJvDockVSChannel;
  Block: TJvDockVSBlockAccess;
  i: Integer;
begin
  if DockPanel is TJvDockVSNETPanel then
  begin
    Channel := TJvDockVSNETPanel(DockPanel).VSChannel;
    for i := 0 to Channel.BlockCount - 1 do
    begin
      Block := TJvDockVSBlockAccess(Channel.Block[i]);
      Block.InactiveBlockWidth := 100;
    end;
  end;
end;

由于目前这是一个受保护的属性,它可能表明它的功能正在建设中。我想 Jedi 的开发团队现在决定只绘制每个非活动选项卡的字形,因为缺少动态处理选项卡宽度的完整实现。例如,您应该能够设置每个选项卡的最小宽度,并且当栏(即它所在的容器)更改高度时,所有选项卡都应该相应地变宽或变窄。

编辑:

由于设计灵活,您可以通过设置 DockServer 的 DockPanelClass 属性来解决该错误。我想必须在设置 Style 属性之前设置该属性。它涉及重写整个 Paint 例程,因为 InactiveBlockWidth 也用于 GetBlockRect,而后者又不是虚拟的:

type
  TJvDockVSBlockAccess = class(TJvDockVSBlock);

  THackJvDockVSNETPanel = class(TJvDockVSNETPanel)
  public
    constructor Create(AOwner: TComponent); override;
  end;

  THackJvDockVSChannel = class(TJvDockVSChannel)
  protected
    procedure Paint; override;
    procedure ResetBlock; override;
    procedure Resize; override;
  end;

const
  InactiveTabWidth = 100;

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
begin
  ...
  JvDockVSNetStyle1.DockPanelClass := THackJvDockVSNETPanel;
end;

{ THackJvDockVSNETPanel }

constructor THackJvDockVSNETPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  VSChannelClass := THackJvDockVSChannel;
end;

{ THackJvDockVSChannel }

procedure THackJvDockVSChannel.Paint;
var
  I: Integer;

  procedure DrawSingleBlock(Block: TJvDockVSBlockAccess);
  var
    DrawRect: TRect;
    I: Integer;
    OldGraphicsMode: Integer;
    VisiblePaneCount: Integer;

    procedure AdjustImagePos;
    begin
      if Align = alLeft then
      begin
        Inc(DrawRect.Left, 3);
        Inc(DrawRect.Top, 4);
      end
      else if Align = alTop then
      begin
        Inc(DrawRect.Left, 4);
        Inc(DrawRect.Top, 2);
      end
      else if Align = alRight then
      begin
        Inc(DrawRect.Left, 4);
        Inc(DrawRect.Top, 4);
      end
      else if Align = alBottom then
      begin
        Inc(DrawRect.Left, 4);
        Inc(DrawRect.Top, 3);
      end;
    end;

  begin
    VisiblePaneCount := 0;
    for I := 0 to Block.VSPaneCount - 1 do
    begin
      if not Block.VSPane[I].Visible then
        Continue;
      GetBlockRect(Block, I, DrawRect);
      Canvas.Brush.Color := TabColor;
      Canvas.FillRect(DrawRect);
      Canvas.Brush.Color := clGray;
      Canvas.FrameRect(DrawRect);
      AdjustImagePos;
      Block.ImageList.Draw(Canvas, DrawRect.Left, DrawRect.Top, I);
      if Align in [alTop, alBottom] then
        Inc(DrawRect.Left, 24)
      else if Align in [alLeft, alRight] then
      begin
        Inc(DrawRect.Top, 24);
        if Align = alLeft then
          DrawRect.Left := 15
        else
          DrawRect.Left := 20;
        DrawRect.Right := DrawRect.Left + (DrawRect.Bottom - DrawRect.Top);
      end;
      Canvas.Brush.Color := TabColor;
      Canvas.Pen.Color := clBlack;
      Dec(DrawRect.Right, 3);
      OldGraphicsMode := SetGraphicsMode(Canvas.Handle, GM_ADVANCED);
      Canvas.Brush.Style := bsClear;
      DrawText(Canvas.Handle, PChar(Block.VSPane[I].DockForm.Caption), -1,
        DrawRect, DT_END_ELLIPSIS or DT_NOCLIP);
      SetGraphicsMode(Canvas.Handle, OldGraphicsMode);
      Inc(VisiblePaneCount);
    end;
    if VisiblePaneCount > 0 then
      CurrentPos := CurrentPos + BlockInterval;
  end;

begin
  ResetBlock;
  CurrentPos := BlockStartOffset;
  for I := 0 to BlockCount - 1 do
    DrawSingleBlock(TJvDockVSBlockAccess(Block[I]));
end;

procedure THackJvDockVSChannel.ResetBlock;
var
  I: Integer;
begin
  inherited ResetBlock;
  for I := 0 to BlockCount - 1 do
    TJvDockVSBlockAccess(Block[I]).InactiveBlockWidth := InactiveTabWidth;
end;

procedure THackJvDockVSChannel.Resize;
begin
  { Here you could widen or narrow the tabs according the total space and
    depending on the number of tabs }
  inherited Resize;
end;

加宽标签示例

于 2011-07-09T08:31:42.063 回答