首先,我们需要了解常用的方法:DrawEllipse;DrawImage;DrawLine;DrawPolygon;DrawRectangle;DrawText等。
其次,我们需要USING下面的包:
Microsoft.SPOT;
Microsoft.SPOT.Input;
Microsoft.SPOT.Presentation;
Microsoft.SPOT.Presentation.Controls;
接着基本代码为:
public class Program : Microsoft.SPOT.Application
{
public static void Main()
{
//创建窗体
WindowsDrawing win = new WindowsDrawing();
win.Height = SystemMetrics.ScreenHeight;
win.Width = SystemMetrics.ScreenWidth;
//运行
new Program().Run(win);
}
//派生一个类并重载
internal sealed class WindowsDrawing: Window
{
public override void OnRender(DrawingContext dc)
{
Color c = ColorUtility.ColorFromRGB(125, 0, 255);
Brush b = new SolidColorBrush(c);
Pen p = new Pen(c);
//设背景为矩形
dc.DrawRectangle(b, p, 0, 0, Width, Height);
//画椭圆形
p=new Pen(Color.Black);
b = new SolidColorBrush(Color.White);
dc.DrawEllipse(b, p, 55,25, 55,25);
//画线
p = new Pen(ColorUtility.ColorFromRGB(255, 0,0),5);
dc.DrawLine(p, 55, 25, 100,80);
//多边行
int[] points = { 10, 220, 50, 200, 0, 170, 50, 120, 80,
110, 90, 100, 55, 200, 60, 220 };
b = new SolidColorBrush(Color.White);
p = new Pen(ColorUtility.ColorFromRGB(0, 255,0),3);
dc.DrawPolygon(b,p, points);
//文字
c= ColorUtility.ColorFromRGB(0, 255, 255);
dc.DrawText(";, Resources.GetFont(Resources.FontResources.small), c, 180, 20);
//位图 (支持bmp,gif,jpg等格式)
dc.DrawImage(Resources.GetBitmap(
Resources.BitmapResources.SMVP),230,130);
}
}
}
大家可以看到,用简单的代码,就可以表现MF的绘图能力。不难吧?