Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

Resizing a TImage at runtime with a mouse

Please, I'm needing resize a TComponent with a mouse. For example when I put a mouse pointer over a border of component I may hold a button and resize it so.

How can I do it?
0
jorgegss
Asked:
jorgegss
1 Solution
 
keashFCommented:
here is an example of how to do it with a button.

just place a button called button1 on a form and assign the events.

var
  Form1: TForm1;
  sizing:boolean;
  oldXY : TPoint;

implementation

{$R *.dfm}

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  // if mouse in lower edge then begin resizing
  if (x> button1.Width-5) and (y > button1.Height-5) then
  begin
    sizing:=true;
    oldxy.X:=x;
    oldxy.y:=y;
    oldXY := button1.ClientToScreen(oldXY);
  end;
end;

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  sizing:=false;
  screen.Cursor:=crDefault;
end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var p:TPoint;
begin
   if sizing then
   begin
     p.X:=x;
     p.y:=y;
     p:=button1.ClientToScreen(p);
     button1.height:=button1.height + p.y-oldXY.y;
     button1.width:=button1.width + p.X-oldXY.x;
     oldXY:=p;
   end else
   begin
   // display sizing cursor if in range
   if (x> button1.Width-5) and (y > button1.Height-5) then
   begin
     screen.cursor:=crSizeNWSE;
   end else screen.Cursor:=crDefault;
   end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 screen.cursor:=crDefault;
end;

this is the theory.
you could now
1) make a component that implements this behavior
2) make a resizable container component (derived from TGraphicControl for example) that can contain other controls and resizes them as it is resized.

the 2nd approach should be the best.

cu
F
0
 
pderuiterCommented:
also see the thread "Components as if in design state" for a similar procedure that will give you changing mouse cursor as well
0
 
CleanupPingCommented:
jorgegss:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
kacorretiredCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept keashF's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now