RAD Studio VCL Reference
|
Lists the panels (TStatusPanel objects) in the status bar.
property Panels: TStatusPanels;
__property TStatusPanels Panels;
The Panels property holds a TStatusPanels—that is, a collection of TStatusPanel objects. At design time, you can add, remove, or modify panels with the Panels editor. To open the Panels editor, select the Panels property in the Object Inspector, then double-click in the Value column to the right or click the ellipsis (...) button.
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 example requires a form with a four-paneled status bar. (Set the Width of the status panels to 150 before running this example). When the user presses a mouse button, moves the mouse, and releases the mouse button, a rectangle is drawn on the form. When the mouse button is released, the rectangle appears on the form’s canvas. Its top-left and bottom-right corners are defined by the location of the mouse pointer when the user pressed and released the mouse button. While the user drags the mouse, the location of the top, left, bottom, and right sides of the rectangle are displayed in the status bar. */ int StartX, StartY; // Declare at the top of the form’s unit // Use this code as the OnMouseDown event handler of the form: void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { StartX = X; StartY = Y; } // Use this code as the OnMouseUp event handler of the form: void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Form1->Canvas->Rectangle(StartX, StartY, X, Y); StatusBar1->Panels->Items[0]->Text = ""; StatusBar1->Panels->Items[1]->Text = ""; StatusBar1->Panels->Items[2]->Text = ""; StatusBar1->Panels->Items[3]->Text = ""; } // Use this code as the OnMouseMove event handler of the form: void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssLeft)) // make sure button is down { if (Y > StartY) { StatusBar1->Panels->Items[0]->Text = "Top: " + IntToStr(StartY); StatusBar1->Panels->Items[2]->Text = "Bottom: " + IntToStr(Y); } else { StatusBar1->Panels->Items[0]->Text = "Top: " + IntToStr(Y); StatusBar1->Panels->Items[2]->Text = "Bottom: " + IntToStr(StartY); } if (X > StartX) { StatusBar1->Panels->Items[1]->Text = "Left: " + IntToStr(StartX); StatusBar1->Panels->Items[3]->Text = "Right: " + IntToStr(X); } else { StatusBar1->Panels->Items[1]->Text = "Left: " + IntToStr(X); StatusBar1->Panels->Items[3]->Text = "Right: " + IntToStr(StartX); } } }
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 example requires a form with a four-paneled status bar. (Set the Width of the status panels to 150 before running this example). When the user presses a mouse button, moves the mouse, and releases the mouse button, a rectangle is drawn on the form. When the mouse button is released, the rectangle appears on the form’s canvas. Its top-left and bottom-right corners are defined by the location of the mouse pointer when the user pressed and released the mouse button. While the user drags the mouse, the location of the top, left, bottom, and right sides of the rectangle are displayed in the status bar. } procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin StartX := X; StartY := Y; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Form1.Canvas.Rectangle(StartX, StartY, X, Y); StatusBar1.Panels[0].Text := ''; StatusBar1.Panels[1].Text := ''; StatusBar1.Panels[2].Text := ''; StatusBar1.Panels[3].Text := ''; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if ssLeft in Shift then { make sure button is down } begin if Y > StartY then begin StatusBar1.Panels[0].Text := 'Top: ' + IntToStr(StartY); StatusBar1.Panels[2].Text := 'Bottom: ' + IntToStr(Y); end else begin StatusBar1.Panels[0].Text := 'Top: ' + IntToStr(Y); StatusBar1.Panels[2].Text := 'Bottom: ' + IntToStr(StartY); end; if X > StartX then begin StatusBar1.Panels[1].Text := 'Left: ' + IntToStr(StartX); StatusBar1.Panels[3].Text := 'Right: ' + IntToStr(X); end else begin StatusBar1.Panels[1].Text := 'Left: ' + IntToStr(X); StatusBar1.Panels[3].Text := 'Right: ' + IntToStr(StartX); end; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|