Solved

How can I move a rectangle around?

Posted on 2002-03-27
10
417 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now