1

I try to do something like when I touch somewhere on the screen - that position show up a circle

But the problem is - everywhere I touch the screen, the circle always appears in the middle of my grid:

public void Draw_Circle(int x, int y)
{
        SolidColorBrush scb_O = new SolidColorBrush(Colors.Red);

        Ellipse elip = new Ellipse();

        elip.Stroke = scb_O;
        elip.StrokeThickness = 2;

        elip.Height = dd;
        elip.Width = dd;
        Canvas.SetLeft(elip, (double)x);
        Canvas.SetTop(elip, (double)y);
        //elip.SetValue(Canvas.TopProperty, (double)x);
        //elip.SetValue(Canvas.LeftProperty, (double)y);

        try
        {
            ContentPanel.Children.Add(elip);
        }
        catch (Exception ex2)
        {
            MessageBox.Show("Error: " + ex2);
        }
    }

And the touch position:

protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
        base.OnMouseLeftButtonDown(e);

        Point p1 = e.GetPosition(null);
        int x = (int)p1.X;
        int y = (int)p1.Y;
        //MessageBox.Show(x + " , " + y + "\n" + p1.X + " , " + p1.Y);

        Draw_Circle(x, y);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3688221
  • 87
  • 1
  • 1
  • 7

2 Answers2

0

http://msdn.microsoft.com/en-us/library/system.windows.shapes.ellipse(v=vs.110).aspx How to add a Click event to an Ellipse in code behind?

Combine these two resourses and implemente them to solve your own problem. First resource shows how to create an ellipse and second resource shows how to call it with a event handler. I hope it may work and help you..

Community
  • 1
  • 1
Ismail Yilmaz
  • 247
  • 1
  • 13
0
elip.HorizontalAlignment = HorizontalAlignment.Left;
elip.VerticalAlignment = VerticalAlignment.Top;
elip.RenderTransform = new TranslateTransform() { X = 10, Y = 50 }
Eminem
  • 7,206
  • 15
  • 53
  • 95