kasbuttonpanel.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. unit KASButtonPanel;
  2. {$mode Delphi}
  3. interface
  4. uses
  5. Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls;
  6. type
  7. { TKASButtonPanel }
  8. TKASButtonPanel = class(TPanel)
  9. private
  10. FSameWidth: Boolean;
  11. FSameHeight: Boolean;
  12. protected
  13. procedure ButtonsAutoSize;
  14. procedure DoAutoSize; override;
  15. public
  16. constructor Create(TheOwner: TComponent); override;
  17. published
  18. property SameWidth: Boolean read FSameWidth write FSameWidth default True;
  19. property SameHeight: Boolean read FSameHeight write FSameHeight default True;
  20. end;
  21. procedure Register;
  22. implementation
  23. uses
  24. StdCtrls;
  25. procedure Register;
  26. begin
  27. RegisterComponents('KASComponents', [TKASButtonPanel]);
  28. end;
  29. { TKASButtonPanel }
  30. procedure TKASButtonPanel.ButtonsAutoSize;
  31. var
  32. Index: Integer;
  33. AControl: TControl;
  34. AMaxWidth, AMaxHeight: Integer;
  35. begin
  36. AMaxWidth:= 0;
  37. AMaxHeight:= 0;
  38. for Index:= 0 to ControlCount - 1 do
  39. begin
  40. AControl:= Controls[Index];
  41. if AControl is TCustomButton then
  42. begin
  43. if FSameWidth and (AControl.Width > AMaxWidth) then AMaxWidth:= AControl.Width;
  44. if FSameHeight and (AControl.Height > AMaxHeight) then AMaxHeight:= AControl.Height;
  45. end;
  46. end;
  47. for Index:= 0 to ControlCount - 1 do
  48. begin
  49. AControl:= Controls[Index];
  50. if AControl is TCustomButton then
  51. begin
  52. if FSameWidth then AControl.Constraints.MinWidth:= AMaxWidth;
  53. if FSameHeight then AControl.Constraints.MinHeight:= AMaxHeight;
  54. end;
  55. end;
  56. end;
  57. procedure TKASButtonPanel.DoAutoSize;
  58. begin
  59. inherited DoAutoSize;
  60. if csDesigning in ComponentState then Exit;
  61. if AutoSize and (FSameWidth or FSameHeight) then ButtonsAutosize;
  62. end;
  63. constructor TKASButtonPanel.Create(TheOwner: TComponent);
  64. begin
  65. FSameWidth:= True;
  66. FSameHeight:= True;
  67. inherited Create(TheOwner);
  68. end;
  69. end.