Forum > Designer

TCustomControl descendant not resizeable in Designer


I have a TCustomControl component which parents a TWincontrol and a TLabel. It autosizes via an overridden CalculatePreferredSize, behaving as I want when instantiated in code.
However, when installed on the component palette and dropped on a form it is selectable, but cannot be resized. It presumably uses the default Lazarus component editor.
Any ideas how to get it to resize in the Designer?

Just to make sure: AutoSize is off when you attempt to resize the control?

How did you position the two controls to each other? Using anchoring is sometimes tricky and can lead to locked situations. In these cases, usage of ChildSizing is easier.

The attached quick-and-dirty unit combines a TLabel and a TEdit, and here resizing works correctly when AutoSize is false:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit combined; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Controls, StdCtrls; type  TCombinedEdit = class(TCustomControl)  private    FLabel: TLabel;    FEdit: TEdit;    function GetCaption: String;    function GetText: String;    procedure SetCaption(const AValue: String);    procedure SetText(const AValue: String);  protected    procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;      WithThemeSpace: Boolean); override;  public    constructor Create(AOwner: TComponent); override;  published    property Caption: String read GetCaption write SetCaption;    property Text: String read GetText write SetText;    property AutoSize default true;  end; procedure Register; implementation procedure Register;begin  RegisterComponents('Misc', [TCombinedEdit]);end;   constructor TCombinedEdit.Create(AOwner: TComponent);begin  inherited;  FLabel := TLabel.Create(self);  FLabel.Parent := self;  FLabel.BorderSpacing.Bottom := 2;  FLabel.WordWrap := true;  FLabel.AutoSize := true;  FLabel.Caption := 'Label';    FEdit := TEdit.Create(self);  FEdit.Parent := self;    Width := 200;  with ChildSizing do  begin    ControlsPerLine := 1;    EnlargeHorizontal := crsHomogenousChildResize;    Layout := cclLeftToRightThenTopToBottom;    VerticalSpacing := 2;  end;  AutoSize := true;end; procedure TCombinedEdit.CalculatePreferredSize(  var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); begin  PreferredHeight := FLabel.Top + FLabel.Height + FLabel.BorderSpacing.Bottom + FEdit.Height;  PreferredWidth := 0;end; function TCombinedEdit.GetCaption: String;begin  Result := FLabel.Caption;end; function TCombinedEdit.GetText: String;begin  Result := FEdit.Text;end; procedure TCombinedEdit.SetCaption(const AValue: String);begin  FLabel.Caption := AValue;  Invalidate;end; procedure TCombinedEdit.SetText(const AValue: String);begin  FEdit.Text := AValue;  Invalidate;end; end.

Thanks, wp. You've put me on the right track with using childsizing rather than anchoring.
I'll share the outcome in due course, I hope.


[0] Message Index

Go to full version