gpt4 book ai didi

delphi - 是否可以控制 JvDockServer 组件中选项卡的显示方式?

转载 作者:行者123 更新时间:2023-12-03 15:51:00 27 4
gpt4 key购买 nike

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

screenshot of overlapping tabs

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

一如既往地感谢——Al C。

最佳答案

正如 ain 评论的那样,我也认为这是一个错误。更准确地说,TJvDockVSChannel.Paint 中绘制选项卡的错误(选项卡内部称为 block )。这样的 block 有一个 protected 属性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;

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

编辑:

由于灵活的设计,您可以通过设置 DockServer 的 DockPanelClass 属性来解决该错误。我认为必须在设置 Style 属性之前设置该属性。它涉及重写整个 Paint 例程,因为 InactiveBlockWidth 也在 GetBlockRect 中使用,而 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;

Sample of widened tabs

关于delphi - 是否可以控制 JvDockServer 组件中选项卡的显示方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6630607/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com