13,141,576 members (56,088 online)
Rate this:
See more:
Hi,

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
v3

Rate this:

## 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:

## 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)

Top Experts
Last 24hrsThis month
 OriginalGriff 215 Graeme_Grant 210 Jochen Arndt 185 ppolymorphe 113 Karthik Bangalore 110
 OriginalGriff 5,092 Graeme_Grant 5,018 ppolymorphe 1,814 Jochen Arndt 1,707 CPallini 1,500

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 16 May 2010