Solved

How can I move a rectangle around?

Posted on 2002-03-27
10
427 Views
Last Modified: 2010-04-04
I am trying to build a mindmap with millions of nodes and information.

I have built a rectange using the Canvas.Rectangle function with x1,y1,x2,yz

But I dont know how to move the finished rectangle around with the mouse while ive clicked the button.

Also how do I show that when I have click on the rectangle that it is at focus.

Could someone help me?
0
Comment
Question by:Ben_iti
10 Comments
 
LVL 4

Expert Comment

by:YodaMage
ID: 6899411
There is a free downloadable component you can find at:

www.torry.ru/sizersother.htm

CompCtrl v2.0

It does what you want and comes with source to tell you how they do it. Note, there is a bug in the component if you go to the resizing code which blows up app's, as the writer did not catch the instance where the user may grab one size of a shape and drag it over the other, resulting in a negative size value. Adding a little code to catch this and not allowing a value less than 10 takes care of this.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6899555
listening
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6899689
I'm not entirly sure on what you want to do but you coucld try something like below:

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Panel1 do
  begin
    BevelInner := bvLowered;
    BevelOuter := bvRaised;
    BevelWidth := 1;
  end;
end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Panel1.Handle, WM_SYSCOMMAND, $F012, 0);
end;

If you want a transparnt rectange then you could try messing around with SetWindowRgn().

Cheers,

Alan
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Expert Comment

by:SteveWaite
ID: 6900656
Try this, here it moves the entire form, so hopefully you can adjust to make use of the coords of your rectangles.

var
  Form1: TForm1;
  MouseIsDown: Boolean;
  X1, Y1: Integer;

implementation

{$R *.DFM}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
// you will need to check the point is inside your rectangle
  X1 := X;
  Y1 := Y;
  MouseIsDown := True;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if MouseIsDown then
  begin
    Left := Left + X - X1;
    Top := Top + Y - Y1;
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  MouseIsDown := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MouseIsDown := False;
end;

0
 
LVL 6

Accepted Solution

by:
zebada earned 50 total points
ID: 6900667
*very* simple code to do what you want is here in a complete working app
http://www.blacky.co.nz/free/wireframe.zip
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6901800
What you really want is giving your graph a user interface.
So each (visible) node needs a control attached. Best make it a TWinControl descendant to get focus handling for free.
The control then gets a sizable border implemented.
You need a carrying TWinControl control which takes care of the connections drawn.
The real drawing algorithm is then determining which node needs a control attached.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 6901801
hello Ben iti, you need to use the Form's MouseMove to test if the cursor is over the Rect and then use the MouseDown to move the Rect, by erase and redraw the Rect, There is a answer I did for a similar question at

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20253019

if that has to much in it for you to deal with, I could redo it so it just does a Move Rect.
0
 

Author Comment

by:Ben_iti
ID: 6956892
Thanks Zebada,

Your from New Zealand, so am I.
Palmerston North.

You're pretty good on Delphi, im not.
You've got a job in programming with Delphi?? Did you go for certification through Borland?

Please reply

Ben
0
 
LVL 6

Expert Comment

by:zebada
ID: 6957045
Hi Ben,

Thanks for the points - by the way that code may not be the best way to do it, it's just an example - there's probably a 100 ways to do it, some better, some not.

I aint half as good as most of the experts on E-E.
I have never been lucky enough to have a full time job programming in Delphi. The only Delphi work I do is for my hobby conencting high performance fuel injected cars to a PC: http://www.starrperformance.com.au/efilivev5.
I've had to write a lot of visual components for this like a scrolling, real-time graphical data logger, Dash board components like Speedometers and Tachometers.

I have no certification from Borland.
All the tricky stuff I learn't here on E-E.

Paul
0
 

Author Comment

by:Ben_iti
ID: 6974512
Go all the way to get that Borland Delphi 6 certificate if I were you.

Right now, if I wasnt a student, I would.
Man you have more knowledge than me, you may have some time. I dont.

Thanks have ufn

Ben
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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