delphi.gif (306 バイト) StatusBarの使い方


ステータスバーコントロールを使うと、フォームに簡単にステータスバーを追加できます。ステータスバーは複数のパネルに分けて使うことができます。ステータスバーの使い方は、ステータスバーの追加を参照してください。

 

toach.gif (917 バイト) ステータスバーのオーナー描画

ステータスバーには、テキストだけでなくグラフィックスも表示できます。グラフィックスを表示するには、オーナー(Owner Draw)描画機能を使います。オーナー描画はSimpleTextにはできません。ステータスバーにステータスパネルを追加して、ステータスパネルのStyleプロパティをpsOwnerDrawに変更しておく必要があります。そして、ステータスバーのOnDrawPanelイベントハンドラを追加し、その中で描画を行います。

次の例は、ステータスパネルを2つ追加して最初のパネルに四角形を描画し、2つ目のパネルにテキストをオーナー描画で表示するものです。

delphi1.gif (322 バイト)
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
begin
    if Panel = StatusBar1.Panels[0] then
      StatusBar.Canvas.Rectangle(Rect.Left + 4, Rect.Top + 3, 30, 20)
   else if Panel = StatusBar1.Panels[1] then
      StatusBar.Canvas.TextOut(Rect.Left + 4, Rect.Top + 3, 'Good morning');
end;