Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a custom Circle control and added in to a canvas control like following code: (Note:- The main form has a button control. It will create a circle control inside Canvas control dynamically.)

_panel.Children.Add(_circle);

Now I need to implement drag and move functionality inside the Canvas control. I have tried to implement using the following code:

Circle.xmal.cs
C#
protected void shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        xMouseLeftButtonDown(sender, e);
    }

    protected void shape_MouseMove(object sender, MouseEventArgs e)
    {
        xMouseMove(sender, e);
    }

    protected void shape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        xMouseLeftButtonUp(sender, e);
    }


Main.xaml.cs
C#
protected void shape_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        source = (UIElement)sender;
        Mouse.Capture(source);
        captured = true;
        x_shape = Canvas.GetLeft(source);
        x_canvas = e.GetPosition(LayoutRoot).X;
        y_shape = Canvas.GetTop(source);
        y_canvas = e.GetPosition(LayoutRoot).Y;
    }

    protected void shape_MouseMove(object sender, MouseEventArgs e)
    {
        if (captured)
        {
            double x = e.GetPosition(LayoutRoot).X;
            double y = e.GetPosition(LayoutRoot).Y;
            x_shape += x - x_canvas;
            Canvas.SetLeft(source, x_shape);
            x_canvas = x;
            y_shape += y - y_canvas;
            Canvas.SetTop(source, y_shape);
            y_canvas = y;
        }
    }

    protected void shape_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        Mouse.Capture(null);
        captured = false;
    }


But its not working. can anyone suggest me how to implement this.
Posted
Comments
Maciej Los 14-Apr-14 5:23am    
"Not working" - is not informative at all!
willington.d 14-Apr-14 5:43am    
Hi Maciej., The concept is, I have to create a IDE like VS2005. I have to create tool box with necessary controls like Button, Label, Textbox etc. I have created tool box and drag and drop options. Now I have to apply properties like VS2500 Control properties. Move the controls, re size Any Idea about this???

1 solution

Please read my comment to the question.

Have a look here: Drag and drop WPF controls[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900