?
Solved

Resizing a TImage at runtime with a mouse

Posted on 2003-02-19
5
Medium Priority
?
372 Views
Last Modified: 2010-04-04
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
Comment
Question by:jorgegss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
keashF earned 800 total points
ID: 7981838
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
 

Expert Comment

by:pderuiter
ID: 7988565
also see the thread "Components as if in design state" for a similar procedure that will give you changing mouse cursor as well
0
 

Expert Comment

by:CleanupPing
ID: 9317186
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
 
LVL 10

Expert Comment

by:kacor
ID: 9927998
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question