Delphi:更改TJvDockTabHostForm的Tab图标

时间:2013-02-04 12:37:12

标签: delphi jedi jvcl

有没有办法在TJvDockVSPopupPanel设置之后更改其标签图标?

问题是我希望在我的程序更改之后将选项卡图标更改为验证图像...

ImageList1: TImageList;

procedure TValidationWindow.UpdateIcon;
var
    i, topValidationError  : integer;
begin
    topValidationError := 3;

    {
        SECTION
        //Set topValidationError value to the specific error that has occurred
        SECTION END
    }

    // Set the Icon to the specific image.
    ImageList1.GetIcon(topValidationError, Self.Icon);
end;

以上仅限第一次使用!任何想法?

编辑:

进一步检查我发现在TJvDockCustomTabControl中有一个FImages:TCustomImageList,但是我还没有找到一种方法来访问FImages,我假设必须有一些方法将我的图标添加到此列表然后只需使用imageindex更改标签图标图像。

解决:

所以最大的问题是访问图像列表,这可以通过允许访问TJVDockTabControl的TJvDockVIDTabPageControl来完成。

更改标签图标的代码是......

if (GetAncestors(Self, 3) is TJvDockTabHostForm) then
    if ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl is TJvDockVIDTabPageControl) then
    begin
        if FTabSheetIndex = - 1 then
            FTabSheetIndex := ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).PageSheets.IndexOf(TJvDockTabSheet(Self.Parent));
        ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Pages[FTabSheetIndex].ImageIndex := x// The icon you want to use
        ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Panel.Refresh;
    end;

我已经包含了FTabSheetIndex,因为对DockHostWindow的更改会导致标签更改,例如在更改之前删除选项卡将导致选项卡索引顺序发生更改,因此可以轻松将其设置为-1并再次找到。

GetAncestors()的信息可以在How can you tell if a TJvDockServer Form is unpinned or pinned?

找到

您还必须将您的图标添加到TJvDockTabPageControl,最好在FormShow事件中完成...

if (GetAncestors(Self, 3) is TJvDockTabHostForm) then
    if ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl is TJvDockVIDTabPageControl) then
    begin
        FTabImageListCount := ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Images.Count;
        for i := 0 to ImageList1.Count - 1 do
        begin
            ImageList1.GetIcon(i,Icon);
            ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Images.AddIcon(icon);
        end;
    end;

但是,如果表单未在应用程序的开头显示,则图标更改功能可能无效,直到您专门单击选项卡以显示它。因此,一旦将表单添加到TJvDockHostForm中,最好添加图标...这仍然是我正在研究的问题,但关键问题已得到解决。

1 个答案:

答案 0 :(得分:0)

所以最大的问题是访问图像列表,这可以通过允许访问TJVDockTabControl的TJvDockVIDTabPageControl来完成。

更改标签图标的代码是......

if (GetAncestors(Self, 3) is TJvDockTabHostForm) then
    if ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl is TJvDockVIDTabPageControl) then
    begin
        if FTabSheetIndex = - 1 then
            FTabSheetIndex := ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).PageSheets.IndexOf(TJvDockTabSheet(Self.Parent));
        ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Pages[FTabSheetIndex].ImageIndex := x// The icon you want to use
        ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Panel.Refresh;
    end;

我已经包含了FTabSheetIndex,因为对DockHostWindow的更改会导致标签更改,例如在更改之前删除选项卡将导致选项卡索引顺序发生更改,因此可以轻松将其设置为-1并再次找到。

GetAncestors()的信息可以在How can you tell if a TJvDockServer Form is unpinned or pinned?

找到

您还必须将您的图标添加到TJvDockTabPageControl,最好在FormShow事件中完成...

if (GetAncestors(Self, 3) is TJvDockTabHostForm) then
    if ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl is TJvDockVIDTabPageControl) then
    begin
        FTabImageListCount := ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Images.Count;
        for i := 0 to ImageList1.Count - 1 do
        begin
            ImageList1.GetIcon(i,Icon);
            ((GetAncestors(Self, 3) as TjvDockTabHostForm).PageControl as TJvDockVIDTabPageControl).Images.AddIcon(icon);
        end;
    end;

但是,如果表单未在应用程序的开头显示,则图标更改功能可能无效,直到您专门单击选项卡以显示它。因此,一旦将表单添加到TJvDockHostForm中,最好添加图标...这仍然是我正在研究的问题,但关键问题已得到解决。