Search code examples
delphidevexpressdelphi-xe7

Change the color of text in a particular dxStatusBar1.Panel


How can you change the text color of a particular dxStatusBar1.Panel ? dxStatusBar is VCL component of Devexpress.


Solution

  • The panels have an OnDrawPanel event. Probably the easiest way is to hook into that event and then paint the panel as you would like it painted. Something like this:

    procedure TFormTest.dxStatusBar1Panels1DrawPanel(Sender: TdxStatusBarPanel;
        ACanvas: TcxCanvas; const ARect: TRect; var ADone: Boolean);
    begin
      Sender.PanelStyle.Painter.FillBackground(dxStatusBar1, Sender, ACanvas, ARect);
      ACanvas.Font.Color := clBlue;
      ACanvas.DrawText(Sender.Text, ARect, cxSingleLine or cxAlignVCenter or cxAlignLeft);
      ADone := True;
    end;
    

    You should add some checks to make sure that the painter is actually assigned and in the case where it's not assigned you would need to paint the background yourself.

    Below is an example of the output.

    Colored Panel Picture