Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Adjust a TWinControls size on RunTime

Title: Adjust a TWinControl's size on RunTime Question: Adjust a TWinControl's size on RunTime Answer: procedure ManipulateControl(WinControl: TWinControl; Shift: TShiftState; X, Y, Precision: integer); var SC_MANIPULATE: Word; begin //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is left of TWinControl*********************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (XPrecision) and (Y begin SC_MANIPULATE := $F001; WinControl.Cursor := crSizeWE; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is Right of TWinControl********************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (X=WinControl.Width-Precision) and (YPrecision) and (Y begin SC_MANIPULATE := $F002; WinControl.Cursor := crSizeWE; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is Top of TWinControl************************************************ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (XPrecision) and (X begin SC_MANIPULATE := $F003; WinControl.Cursor := crSizeNS; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is left and Top of TWinControl*************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (X begin SC_MANIPULATE := $F004; WinControl.Cursor := crSizeNWSE; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is right and Top of TWinControl************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (X=WinControl.Width-Precision) and (Y begin SC_MANIPULATE := $F005; WinControl.Cursor := crSizeNESW ; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is bottom of TWinControl********************************************* //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (XPrecision) and (X=WinControl.Height-Precision) then begin SC_MANIPULATE := $F006; WinControl.Cursor := crSizeNS; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is left and bottom of TWinControl************************************ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (X=WinControl.Height-Precision) then begin SC_MANIPULATE := $F007; WinControl.Cursor := crSizeNESW; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is right and bottom of TWinControl*********************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (X=WinControl.Width-Precision) and (Y=WinControl.Height-Precision) then begin SC_MANIPULATE := $F008; WinControl.Cursor := crSizeNWSE; end else //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Cursor is ClientRect of TWinControl***************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (XPrecision) and (YPrecision) and (X begin SC_MANIPULATE := $F009; WinControl.Cursor := crSizeAll; end else begin SC_MANIPULATE := $F000; WinControl.Cursor := crDefault; end; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if Shift=[ssLeft] then begin ReleaseCapture; WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0); end; end; example: (OnMouseMove Event) procedure TForm1.MoveWinControl(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin ManipulateControl(Sender as TWinControl, Shift, X, Y, 5); end;