RAD Studio VCL Reference
|
Provides runtime access to the status bar's drawing surface.
property Canvas: TCanvas;
__property TCanvas Canvas;
The read-only Canvas property provides access to the status bar's drawing surface that you can use when implementing a handler for the OnDrawPanel event.
C++ Examples:
/* The following code is the OnDrawPanel event handler of a status bar. It draws each panel of the status bar, adding text and icons stored in ImageList1. The image list contains as many icons as there are header sections. This example requires a populated image list and a statusbar with several panels added to the Panels property. Select each panel and set the Style property to psOwnerDraw. */ void __fastcall TForm1::StatusBar1DrawPanel(TStatusBar *StatusBar, TStatusPanel *Panel, const TRect &Rect) { TCanvas *canvas = StatusBar->Canvas; canvas->Brush->Color = clRed; canvas->FillRect(Rect); canvas->Font->Color = clYellow; ImageList1->Draw(canvas,Rect.Left,Rect.Top, Panel->Index, true); canvas->TextOut(Rect.left + 30, Rect.top + 2, "Panel" + IntToStr(Panel->Index)); }
/* The following code uses ClientRect to find and draw a line from the top left to the bottom right of the current control. Select a TControl in the ListBox list. This example assumes that the current object is a descendent of TControl and has a public Canvas property. */ { TPoint APoint = Point(X, Y); int Index = ListBox1->ItemAtPos(APoint, True); TStatusBar *myStatusBar; TClass ClassRef = ListBox1->Items->Objects[Index]->ClassType(); if (String(ClassRef->ClassName()) == "TStatusBar") { myStatusBar = dynamic_cast<TStatusBar *>(ListBox1->Items->Objects[Index]); // make sure we are using the TControls canvas and not the from's! myStatusBar->Canvas->MoveTo(myStatusBar->ClientRect.Left, myStatusBar->ClientRect.Top); myStatusBar->Canvas->LineTo(myStatusBar->ClientRect.Right, myStatusBar->ClientRect.Bottom); myStatusBar = NULL; } }
Delphi Examples:
{ The following code is the OnDrawPanel event handler of a status bar. It draws each panel of the status bar, adding text and icons stored in ImageList1. The image list contains as many icons as there are header sections. This example requires a populated image list and a statusbar with several panels added to the Panels property. Select each panel and set the Style property to psOwnerDraw. } procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect); begin with StatusBar1.Canvas do begin Brush.Color := clRed; FillRect(Rect); Font.Color := clYellow; ImageList1.Draw(StatusBar1.Canvas,Rect.Left,Rect.Top,Panel.Index); TextOut(Rect.left + 30, Rect.top + 2, 'Panel' + IntToStr(Panel.Index)); end; end;
{ The following code uses ClientRect to find and draw a line from the top left to the bottom right of the current control. Select a TControl in the ListBox list. This example assumes that the current object is a descendent of TControl and has a public Canvas property. } if (ListBox1.Items.Objects[Index] is TStatusBar) then begin myStatusBar:= (ListBox1.Items.Objects[Index] as TStatusBar); with myStatusBar.ClientRect do begin // make sure we are using the TControl's canvas and not the form's! myStatusBar.Canvas.MoveTo(Left, Top); myStatusBar.Canvas.LineTo(Right, Bottom); end; myStatusBar:= nil; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|