Sign in to follow this  
carmellose

[.net] C# conception problem

Recommended Posts

carmellose    122
hi guys, well, i'm new to C# and i have a conception problem. I want to draw objects on a canvas and be able to move them. To do this, i implemented a class, which has a function which returns the Shape of the object :
class Module {

// ... members, etc
public Shape getShape();
}



When i draw my object on canvas, i just basically do:
myCanvas.Children.Add( myObject->getShape() ) ;



This works. However, when i want to move my object, i can only have information to the Shape I drew but not the Object it bound to. I basicaly have an event on the canvas, which reacts when the mouse clicks the shape drawn:
private void myCanvas_MouseLeftButtonDown(object sender, MouseEventArgs e)
        { 

         }


But there i have only access to the shape, part of the canvas children, but not the Module it is linked to. How can i manage to have access to the object the shape is related to ? So i can move my objects. If you have any advice ... thank you! cheers

Share this post


Link to post
Share on other sites
Pixar    122
Module myObjects = new Module[..];
..
myCanvas.Children.Add(myObjects[index].getShape());
..
private void myCanvas_MouseLeftButtonDown(object sender, MouseEventArgs e)
{
myObject[index].Move(..);
myCanvas.Children.Clear(..);
myCanvas.Children.Add(myObjects[index].getShape());
}

Share this post


Link to post
Share on other sites
ernow    732
For speed (and a bit dirty) you could set the Tag property (or any other added property of the correct type) of the shape to the object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this