سؤال

Is there a way to change the Tab Icon of a TJvDockVSPopupPanel after it has already been set?

The problem is that I want to change the Tab Icon to a validation image after a change in my program via...

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;

The above will work the first time only! Any Ideas?

Edit:

On further inspection I've found that there is a FImages:TCustomImageList in TJvDockCustomTabControl, However I have not found a way to access FImages yet, I'm assuming there must be some way to add my icons to this list and then just change the Tab Icon image using the imageindex.

SOLVED:

So the biggest issue was accessing the images list, this can be done through the TJvDockVIDTabPageControl which allows access to TJVDockTabControl.

The code to change the tab icon is...

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;

I've included FTabSheetIndex because changes to the DockHostWindow can cause the tabs to change e.g. removing a tab before the one your changing will cause the tab index order to change so it can easily be set to -1 and found again.

Info on GetAncestors() can be found here How can you tell if a TJvDockServer Form is unpinned or pinned?

You will also have to add your icons to the TJvDockTabPageControl, best done on the FormShow event...

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;

However, if the form is not shown on the start of your application, icon changing functions may not work until you've specifically clicked on the tab to show it. Therefore its probably best to add the icons as soon as your form has been added to the TJvDockHostForm... This is still something I'm looking into, however the key issue has been addressed.

هل كانت مفيدة؟

المحلول

So the biggest issue was accessing the images list, this can be done through the TJvDockVIDTabPageControl which allows access to TJVDockTabControl.

The code to change the tab icon is...

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;

I've included FTabSheetIndex because changes to the DockHostWindow can cause the tabs to change e.g. removing a tab before the one your changing will cause the tab index order to change so it can easily be set to -1 and found again.

Info on GetAncestors() can be found here How can you tell if a TJvDockServer Form is unpinned or pinned?

You will also have to add your icons to the TJvDockTabPageControl, best done on the FormShow event...

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;

However, if the form is not shown on the start of your application, icon changing functions may not work until you've specifically clicked on the tab to show it. Therefore its probably best to add the icons as soon as your form has been added to the TJvDockHostForm... This is still something I'm looking into, however the key issue has been addressed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top