Solved

How can I move a rectangle around?

Posted on 2002-03-27
10
432 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
Independent Software Vendors: 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 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 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mobile Keyboard covers the display of the TMemo 3 102
Dev Express grid collapse 2 47
Delphi...Split view - idea? 1 114
Way to create an iPhone app for my customers 8 42
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…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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