在画布上画东西 [英] Drawing things on a Canvas

查看:21
本文介绍了在画布上画东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在 Windows Phone 的 C# 画布上绘制一些东西?

好吧,让我说得更清楚一点.

假设用户在画布上的 386,43 处向下敲击手指.(画布为 768 x 480)

我希望我的应用程序能够通过在画布上的 386,43 处放置一个红点来做出响应.

没有使用 Canvas 的任何经验.

如果这个问题太复杂而无法在一个问题中回答(可能是这样),给我链接到其他包含 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.

推荐答案

有多种方法可以做到这一点.根据红点的性质,您可以将其设为 UserControl.对于基本圆,您可以简单地处理画布的 ManipulationStarted 事件.

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

这篇关于在画布上画东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆