locked
How to create a path in wpf? RRS feed

  • Question

  • My english is poor. But I must solve the problem.

    I need to create a program which the user can create the path by themselves. 

    The orginal demand is to  clip  specified region in an  image .I think, first ,save  a path which created by user ,the clip the image.Now how to create the complex path that used mouse click.

    Friday, July 19, 2013 6:38 AM

Answers

  • Hi Zhenhua,

    I am a bit confused by the description. But I think you may need to create a path in WPF.

    The following example shows how to create a Path element and set its properties by using code.

    //Add the Path Element
    myPath = new Path();
    myPath.Stroke = System.Windows.Media.Brushes.Black;
    myPath.Fill = System.Windows.Media.Brushes.MediumSlateBlue;
    myPath.StrokeThickness = 4;
    myPath.HorizontalAlignment = HorizontalAlignment.Left;
    myPath.VerticalAlignment = VerticalAlignment.Center;
    EllipseGeometry myEllipseGeometry = new EllipseGeometry();
    myEllipseGeometry.Center = new System.Windows.Point(50,50);
    myEllipseGeometry.RadiusX = 25;
    myEllipseGeometry.RadiusY = 25;
    myPath.Data = myEllipseGeometry;
    myGrid.Children.Add(myPath);

    For more information, please refer to:http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.aspx

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Lisa Zhu Saturday, July 27, 2013 3:43 AM
    Tuesday, July 23, 2013 8:56 AM

All replies

  • Hi Zhenhua,

    I am a bit confused by the description. But I think you may need to create a path in WPF.

    The following example shows how to create a Path element and set its properties by using code.

    //Add the Path Element
    myPath = new Path();
    myPath.Stroke = System.Windows.Media.Brushes.Black;
    myPath.Fill = System.Windows.Media.Brushes.MediumSlateBlue;
    myPath.StrokeThickness = 4;
    myPath.HorizontalAlignment = HorizontalAlignment.Left;
    myPath.VerticalAlignment = VerticalAlignment.Center;
    EllipseGeometry myEllipseGeometry = new EllipseGeometry();
    myEllipseGeometry.Center = new System.Windows.Point(50,50);
    myEllipseGeometry.RadiusX = 25;
    myEllipseGeometry.RadiusY = 25;
    myPath.Data = myEllipseGeometry;
    myGrid.Children.Add(myPath);

    For more information, please refer to:http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.aspx

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Lisa Zhu Saturday, July 27, 2013 3:43 AM
    Tuesday, July 23, 2013 8:56 AM
  • Hi Zhenhua,

    I provisionally marked my reply as answer. Please  feel  free to unmark it if you think the information does not help.

    Thanks for your understanding.

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, July 27, 2013 3:44 AM
  • 查看我问的另一个问题,这个问题和另一个问题已经解决。

    还有就是问下,怎么标记的你的答案为正确答案,刚来这里不知道怎么弄,英语也看不怎么懂。

    Monday, July 29, 2013 3:26 AM