Home › Forums › Konopka Signature VCL Controls (formerly Raize Components) › problem with TRzPageControl
Tagged: TRzPageControl
- This topic has 2 replies, 2 voices, and was last updated 2021-01-08 at 11:01 pm by Steve Black.
-
AuthorPosts
-
-
January 8, 2021 at 6:07 pm #2318
I am using version 5.5.1 and on the TRzPageControl when I set the OnPaintTabBackground event to set different colors for the tab. It works great but if I hide one of the the tabs the ATabIndex seems to be off and following tabs are the wrong color. I set the tag for the tabsheets alternating between 0 and 1. works fine unless I hide a tab then ATabIndex gives me the previously hidden index.
very simplified sample of my code (sorry about the formatting):
procedure RzPageControlPaintTabBackground(Sender: TObject;
ACanvas: TCanvas;
ATabIndex: Integer;
const ARect: TRect;
var Handled: Boolean);
// *****************************************************************************
// this proc will color the tabs yellow for some tabs
// white for other tabs base on the TabSheet tag
// tabsheet tag = 1 white tabs
// tag = 0 yellow tabs
// *****************************************************************************
beginwith (Sender As TRzPageControl).Pages[ATabIndex] do begin
if (tag = 0) then // if tab is set to tag = 0
ACanvas.Brush.Color := clYELLOW // color yellow
else // else
ACanvas.Brush.Color := clWhite; // color white
end;ACanvas.FillRect(ARect); // paint the tab
Handled := True; // show its handledend; // of RzPageControlPaintTabBackground
- This topic was modified 3 years, 10 months ago by Steve Black.
-
January 8, 2021 at 10:06 pm #2320
Hi Steve,
For a TRzTabSheet in a TRzPageControl, there is a TabIndex and a PageIndex. If all the tabs are visible, then the two values will be the same. However, if any of the tab sheets have their TabVisible property set to False, the TabIndex and PageIndex for a specific TRzTabSheet may indeed be different. The PageIndex always represents the “index” of the particular tab sheet in relation to the other pages in the page control. The TabIndex represents the index of the physical tab displayed that is associated with that tab sheet.
You are getting odd results because you are indexing into the Pages collection using a TabIndex instead of a PageIndex. But the OnPaintTabBackground event does not provide a PageIndex, just a TabIndex. Fortunately, there is a PageForTab method available to handle that. If you change your method to the following, you will get the behavior you are expecting:
procedure TForm14.RzPageControl1PaintTabBackground(Sender: TObject; ACanvas: TCanvas; ATabIndex: Integer; const ARect: TRect; var Handled: Boolean); begin with (Sender As TRzPageControl).PageForTab( ATabIndex ) do begin if (tag = 0) then // if tab is set to tag = 0 ACanvas.Brush.Color := clYELLOW // color yellow else // else ACanvas.Brush.Color := clWhite; // color white end; ACanvas.FillRect(ARect); // paint the tab Handled := True; // show its handled end;
Ray
-
January 8, 2021 at 11:01 pm #2321
Ray,
This was exactly what I was needing.
Thank you for the great support.
I have been using your stuff since Delphi 3.
-
-
AuthorPosts
- You must be logged in to reply to this topic.