Click here to Skip to main content
13,141,576 members (56,088 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I added a Rectangle to a Canvas like this:
Canvas.SetTop(myRectangle, 150);
Canvas.SetLeft(myRectangle, 80);

Now I want to move the rectangle to other place, say (100, 100).
What is the best way to do this ?

Thanks !

I'll explain what I'm trying to do. I want user to be able to draw circles on a Canvas. First, user clicks somewhere on the Canvas to define circle's center. Then, when the mouse is moved, I would like to draw a circle according to the current mouse position (the radius is the distance between the current mouse position and the circle's center). I thought to implement this functionality by adding a new Ellipse to Canvas.Children, and then to move this Ellipse and change it's radius with each mouse movement. Am I on the right way ?

Can someone help me with this, please ?
Posted 4-Jan-10 8:38am
Updated 4-Jan-10 23:15pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

When you answer yourself, your question is no longer 'unanswered', which will affect how many people will look at it. It also means when someone goes to reply, they can't see your second post. Edit your post to add detail if you need to, don't reply.

Yes, I think you're on the right track.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

This is a two part process. Part one; create circle on the mousedown and add it to the canvas. Part two; change the circle radius until a mouseup event ends the process.

First the circle must be drawn and the mousemove event must redraw the single circle as the mouse moves relative to the center of the circle. A mousedown event starts the drawing process. Once the desired circle radius is selected by a mouseup event, the circle will be locked into the view.

By keeping a reference to the circle element, its properties can be adjusted without regard to the canvas. So, on the mousedown, add the circle to the canvas. Update the circle radius and the canvas as the mouse moves. Then release the circle reference after the mouseup event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 16 May 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100