物联网智能网关-04】WinForm for .NET MF 功能一览
.Net Micro Framework界面开发官方标准功能仅支持WPF方式,并且所谓的WPF开发和Windows平台上的WPF有很大的区别,即不支持可视化界面设计,也不支持XML方式界面格式定义,另外提供的控件也很少,又不含事件处理,所以使用上相对繁琐,需要自己写很多额外代码。 于是我在2009年底,自行开发了System.Windows.Froms库,相关内容可以参见我当时所写的博客文章《开源System.Windows.Forms库,让.Net Micro Framework界面开发和上位机一样简单》。2010年5月份所写的那篇《RFID技术在.Net Micro Framework中的应用》博文中所显示的演示界面,就是用System.Windows.Froms库开发的。 后来基于Cortex-M3(STM32F103)内核移植了.NET Micro Framework系统,由于STM32F103的芯片主频较低(72M),运行WPF和System.Windows.Froms库比较吃力(而以前的.NET MF板子大部分都是原来WINCE的开发板,主频和资源比较丰富,所以无论运行WPF还是System.Windows.Froms库都是蛮流畅的)。所以system.Windows.Froms库开发完毕后,做了几个Demo后,基本上就搁置了。另外又重新花时间开发了轻量级的界面开发库TinyGUI(相关博文请参见《【玩转.Net MF–06】为Cortex-M3打造轻量级TinyGUI》)。 M3系统升级到STM32F207后,主频提升为120M,运行WPF和System.Windows.Froms库基本上问题不大了,所以对原先的System.Windows.Froms库又进行了升级改进。 以前的System.Windows.Froms库主要模仿WINCE界面开发的,需要用触摸笔才能操作,目前这种操作方式早就淘汰了,所以为了支持手指直接操作,主要从以下几个方面入手进行了改造。 (1)、重新编写了软键盘,支持手指单击输入; (2)、默认字体由原来的12变为16,为了便于操控,控件也进行了扩大处理; (3)、去掉了任务栏; (4)、去掉任务菜单; (5)、窗体界面大小覆盖全屏; 控件简介 System.Windows.Form目前包括Button、TextBox、ListBox、ComboBox、CheckBox、GroupBox、RadioButton、PictureBox、ProgressBar、VScrollBar、HScrollBar等11种常用控件,此外还提供了MessageBox方法,使用方法和Windows平台的winform保持一致。 包含两类窗体、普通窗体及模式窗体,含义和windows平台相同。 软键盘简介 软键盘一共四个不同界面,通过上面的功能键进行切换。 目前还不支持中文输入。 Graphics类简介 如果用户比较喜欢重载OnPaint用Graphics类进行编程,那么和在windows或wince编程中的体验完全一样。不仅如此Graphics类还扩展了一些函数,比如支持图片透明、渐变、圆角矩形绘制等等方法。 Graphics类的声明如下: public sealed class Graphics : Microsoft.SPOT.DispatcherObject, IDisposable { public bool EmptyClipRect; public Graphics(Bitmap bmp); public Graphics(int width, int height); public Bitmap Bitmap { get; } public Rectangle Clip { get; set; } public int Height { get; } public int Width { get; } public void BlendImage(Bitmap source, int destinationX, int destinationY, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity); public void Clear(Color color); public static Size ComputeTextExtent(string text, Font font); public static Size ComputeTextExtent(string text, Font font, int availableWidth); public void Dispose(); public void DrawEllipse(Pen pen, Rectangle rect); public void DrawEllipse(Pen pen, int x, int y, int width, int height); public void DrawImage(Bitmap image, int x, int y); public void DrawImage(Bitmap image, int destinationX, int destinationY, int sourceX, int sourceY, int sourceWidth, int sourceHeight); public void DrawLine(Pen pen, int x0, int y0, ushort Data); public void DrawLine(Pen pen, int x0, int y0, int x1, int y1); public void DrawPolygon(Pen pen, Point[] points); public void DrawPolygon(Pen pen, Point[] points, bool Sealed); public void DrawRectangle(Pen pen, Rectangle rect); public void DrawRectangle(Pen pen, int x, int y, int width, int height); public void DrawRoundRect(Pen pen, Rectangle rect, int rx, int ry); public void DrawRoundRect(Pen pen, int x, int y, int width, int height, int rx, int ry); public void DrawString(string s, Font font, Brush brush, Rectangle rect); public void DrawString(string s, Font font, Brush brush, int x, int y); public void DrawString(string s, Font font, Brush brush, Rectangle rect, StringFormat format); public void FillEllipse(Brush brush, Rectangle rect); public void FillEllipse(Brush brush, int x, int y, int width, int height); public void FillPolygon(Brush brush, Point[] points); public void FillRectangle(Brush brush, Rectangle rect); public void FillRectangle(Brush brush, int x, int y, int width, int height); public void GetTranslation(out int x, out int y); public void ResetClip(); public void RotateImage(int angle, int destinationX, int destinationY, Bitmap bitmap, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity); public void Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity); public void SetPixel(Color color, int x, int y); public void StretchImage(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity); public void TileImage(int xDst, int yDst, Bitmap bitmap, int width, int height, ushort opacity); public void Translate(int dx, int dy); } 界面设计简介 由于.Net Micro Framework的IDE开发环境并不支持所见即所得的窗体设计功能,所以我们可以用.Net Framework和.Net Compact Framework开发环境设计窗体,然后把相关窗体文件(如Form1.cs和Form1.designer.cs文件)直接导入到.Net Micro Framework工程中,稍加删减即可为.Net Micro Framework所用。 (window 控件的字体可以设置为:字体"Arial" 大小11.25F,这种字体和底层设备的字体大小比较接近 ) 关于字体库 由于字体文件相对较大,所以YFSoft.Font库文件是全开源的,用户可以根据需要自行定义字体,设置好进行编译,替换系统所提供的YFSoft.Font.*文件即可。 public Font(string name, float emSize, FontStyle style) { switch (this._name) { default: case "Arial": switch (style) { //case FontStyle.Bold: //_value = YFResource.GetFont(YFResource.FontResources.YFArial16B); //break; default: case FontStyle.Regular: _value = YFResource.GetFont(YFResource.FontResources.YFArial16); break; } break; } this._size = emSize; this._style = style; } 根据需要上述代码进行必要的调整,理论上可以支持任意字体了。 关于.NET MF字体如何定制,请参见我以前写的博文《.Net Micro Framework研究—中文显示》和《.Net Micro Framework研究—Tinyfnt字体研究》。 字体工具下载:http://www.sky-walker.com.cn/MFRelease/Tools/YFTFConvert.rar 未来发展规划 (1)、采用组态软件进行界面设计,并自动生成界面相关的代码。 (2)、再扩展几个工业用控件,比如动态曲线,表格,仪表盘显示等等。 演示视频 视频播放地址:http://v.youku.com/v_show/id_XNDI2NzM4Mjk2.html 从演示效果上看,添加比较多的控件,性能还不尽人意。不过这是基于STM32F207(主频120M)测试的,后续采用STM32F407(主频168M)的芯片,性能会有比较大的改善(当然本框架从软件角度还会继续进行性能优化),想以前在STM32F103(主频72M)芯片上,这个框架根本跑步起来。期待ST推出性能更强大的Cortex-M3或Cortex-M4芯片。 当然如果你需要在当前平台,界面跑得更快,那只有先选择TinyGUI了,不过在写代码上,您自己得多下点功夫了。 下载地址:http://www.sky-walker.com.cn/MFRelease/library/V42/YFSoft.WinForm.rar MF简介:http://blog.csdn.net/yefanqiu/article/details/5711770 MF资料:http://www.sky-walker.com.cn/News.asp?Id=25 本文转自yefanqiu51CTO博客,原文链接:http://blog.51cto.com/yfsoft/929614,如需转载请自行联系原作者