unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls;
type
  TForm1 = class(TForm)
    sb: TStatusBar;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure sbDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
      const Rect: TRect);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
var
  edt:Tedit;
  cmb:TComboBox;
  btn:Tbutton;{$R *.DFM}//1.设状态条某一panel的Style为psOwnerDraw.
//2.在状态条的OnDrawPanel事件中写代码:
//我放了3个控件进去procedure TForm1.Button2Click(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to 2 do
   sb.Panels[i].Style := psOwnerDraw;  if edt=nil then
  begin
    edt:=TEdit.Create(self);
    edt.Parent := sb;  end;
  if cmb=nil then
  begin
    cmb:=TComboBox.Create(self);
    cmb.Parent := sb;
  end;
  if btn=nil then
  begin
    btn := TButton.Create(self);
    btn.Parent := sb;
  end;end;procedure TForm1.sbDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
  const Rect: TRect);
begin
  if Panel =sb.Panels[0] then
  begin
    edt.Width := Rect.Right-Rect.left;
    edt.Left:=Rect.Left;
    edt.Height  := Rect.Bottom-Rect.Top;
    edt.Top := Rect.Top;
  end;
  if Panel=sb.Panels[1] then
  begin
    cmb.Width := Rect.Right-Rect.left;
    cmb.Left:=Rect.Left;
    cmb.Height  := Rect.Bottom-Rect.Top;
    cmb.Top := Rect.Top;
  end;
  if Panel=sb.Panels[2] then
  begin
    btn.Width := Rect.Right-Rect.left;
    btn.Left:=Rect.Left;
    btn.Height  := Rect.Bottom-Rect.Top;
    btn.Top := Rect.Top;
  end;
end;end.