problem with TRzPageControl

Viewing 2 reply threads
  • Author
    Posts
    • #2318
      Steve Black
      Participant

        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
        // *****************************************************************************
        begin

        with (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 handled

        end; // of RzPageControlPaintTabBackground

        • This topic was modified 3 years, 4 months ago by Steve Black.
      • #2320
        Ray Konopka
        Keymaster

          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

        • #2321
          Steve Black
          Participant

            Ray,

            This was exactly what I was needing.

            Thank you for the great support.

            I have been using your stuff since Delphi 3.

             

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.