Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I move a rectangle around?

Posted on 2002-03-27
10
Medium Priority
?
449 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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 34

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 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