Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

How can I move a rectangle around?

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
Ben_iti
Asked:
Ben_iti
1 Solution
 
YodaMageCommented:
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
 
ginsonicCommented:
listening
0
 
alanwhincupCommented:
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!

 
SteveWaiteCommented:
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
 
zebadaCommented:
*very* simple code to do what you want is here in a complete working app
http://www.blacky.co.nz/free/wireframe.zip
0
 
robert_marquardtCommented:
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
 
Slick812Commented:
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
 
Ben_itiAuthor Commented:
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
 
zebadaCommented:
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
 
Ben_itiAuthor Commented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now