Mega Code Archive

 
Categories / Delphi / VCL
 

Preventing components from resizing

Question: How can I prevent resizing of my component at design-time? Answer: Have your constructor set the default size of the object. Override the SetBounds method, and then check the component state. If it is in design mode (csDesigning in ComponentState) simply pass the default values for width and heights to the inherited SetBounds, otherwise you pass the parameters unchanged. Example: procedure TVu.SetBounds(ALeft : integer; ATop : integer; AWidth : integer; AHeight : integer); begin if csdesigning in componentstate then begin AWidth := 50; AHeight := 50; inherited; end;