Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing things on a Canvas

How would I draw something on a Canvas in C# for Windows Phone?

Okay, let me be a little more clear.

Say the user taps his finger down at 386,43 on the canvas. (the canvas is 768 by 480)

I would like my application to be able to respond by placing a red dot at 386,43 on the canvas.

I have no prior experience with Canvas whatsoever.

If this is too complex to be answered in one question (which it probably is), please give me links to other websites with Canvas and Drawing articles.

like image 556
JavaAndCSharp Avatar asked May 15 '11 14:05

JavaAndCSharp


People also ask

What can we draw on a canvas?

The primary types of materials used to draw on canvas are graphite pencils, pigment-based colored art pencils, watercolor pencils, soft and oil pastels, and charcoal. Graphite pencils can be used to draw on canvas, but must be sealed with a fixative before they are permanent.

What is the best way to draw on canvas?

Whether you make your own or you purchase it, transfer paper such as graphite or carbon transfer paper is a great way to transfer a sketch or drawing onto the canvas. The lines it creates tend to hold out a little better on canvas than pencil or charcoal. And a sheet can be used multiple times.


1 Answers

There are various ways of doing this. Depending on the nature of the red dot, you could make it a UserControl. For a basic circle, you can simply handle your canvas' ManipulationStarted event.

private void myCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{

            Ellipse el = new Ellipse();
            el.Width = 10;
            el.Height = 10;
            el.Fill = new SolidColorBrush(Colors.Red);
            Canvas.SetLeft(el, e.ManipulationOrigin.X);
            Canvas.SetTop(el, e.ManipulationOrigin.Y);
            myCanvas.Children.Add(el);
}
like image 96
keyboardP Avatar answered Oct 21 '22 16:10

keyboardP