• Advertisement
Sign in to follow this  

[.net] C# conception problem

This topic is 2869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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());
}

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement