[.net] C# conception problem

Started by
2 comments, last by ernow 14 years, 1 month ago
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
Advertisement
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());
}
thanks Pixar!!

so i have to declare a Module manager - sort of - right ?
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.

This topic is closed to new replies.

Advertisement