Author: Tomas Rutkauskas How to create a TStatusBar with resizable panels Answer: In this demo the TStatusBar has three panels. Only panels 1 and 2 need to be adjustable and each has a set minimum width of 20. The StatusBar OnResize event is used to keep the panels in view, regardless of form resizing, except where the StatusBar width is less than 40. 1 { ... } 2 private 3 {Private declarations} 4 StatusMouseDown: Boolean; 5 Split: Integer; 6 { ... } 7 8 procedure TMainForm.FormCreate(Sender: TObject); 9 begin 10 StatusMouseDown := false; 11 end; 12 13 procedure TMainForm.StatusBar1MouseUp(Sender: TObject; 14 Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 15 begin 16 StatusMouseDown := false; 17 end; 18 19 procedure TMainForm.StatusBar1MouseDown(Sender: TObject; 20 Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 21 var 22 S1, S2: Integer; 23 begin 24 if Button = mbLeft then 25 begin 26 StatusMouseDown := true; 27 Split := 0; 28 S1 := StatusBar1.Panels[0].Width; 29 S2 := StatusBar1.Panels[1].Width + S1; 30 if ((X > S1 - 3) and (X < (S1 + 3))) then 31 Split := 1 32 else if ((X > S2 - 3) and (X < (S2 + 3))) then 33 Split := 2; 34 end; 35 end; 36 37 procedure TMainForm.StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: 38 Integer); 39 var 40 S1, S2, S3: Integer; 41 Split1, Split2: Boolean; 42 begin 43 Split1 := false; 44 Split2 := false; 45 S1 := StatusBar1.Panels[0].Width; 46 S2 := StatusBar1.Panels[1].Width + StatusBar1.Panels[0].Width; 47 S3 := StatusBar1.Width; 48 if ((X > S1 - 3) and (X < (S1 + 3))) then 49 Split1 := true 50 else if ((X > S2 - 3) and (X < (S2 + 3))) then 51 Split2 := true; 52 if (Split1 or Split2) then 53 StatusBar1.Cursor := crHSplit 54 else 55 StatusBar1.Cursor := crDefault; 56 if StatusMouseDown then 57 begin 58 if (Split = 1) then 59 begin 60 if (X < 20) then 61 StatusBar1.Panels[0].Width := 20 62 else if (X > (S3 - 40)) then 63 begin 64 StatusBar1.Panels[0].Width := S3 - 40; 65 StatusBar1.Panels[1].Width := S3 - S1 - 20; 66 end 67 else if (X >= 20) and (X <= S3 - 20) then 68 begin 69 StatusBar1.Panels[0].Width := X; 70 if ((X + StatusBar1.Panels[1].Width + 20) >= S3) then 71 StatusBar1.Panels[1].Width := S3 - X - 20; 72 end; 73 end; 74 if (Split = 2) then 75 begin 76 if (X < (S1 + 20)) then 77 StatusBar1.Panels[1].Width := 20 78 else if (X > (S3 - 20)) then 79 StatusBar1.Panels[1].Width := S3 - S1 - 20 80 else if (X >= S1 + 20) and (X <= S3 - 20) then 81 StatusBar1.Panels[1].Width := X - S1; 82 end; 83 end; 84 end; 85 86 procedure TMainForm.StatusBar1Resize(Sender: TObject); 87 var 88 S1, S2, S3: Integer; 89 begin 90 S1 := StatusBar1.Panels[0].Width; 91 S2 := StatusBar1.Panels[1].Width + StatusBar1.Panels[0].Width; 92 S3 := StatusBar1.Width; 93 if (S1 >= (S3 - 40)) then 94 begin 95 StatusBar1.Panels[0].Width := S3 - 40; 96 StatusBar1.Panels[1].Width := 20; 97 end 98 else if (S2 >= (S3 - 20)) then 99 StatusBar1.Panels[1].Width := S3 - S1 - 20; 100 end;