【物联网智能网关-04】WinForm for .NET MF 功能一览

简介:  .Net Micro Framework界面开发官方标准功能仅支持WPF方式,并且所谓的WPF开发和Windows平台上的WPF有很大的区别,即不支持可视化界面设计,也不支持XML方式界面格式定义,另外提供的控件也很少,又不含事件处理,所以使用上相对繁琐,需要自己写很多额外代码。

 .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平台相同。
image.png

软键盘简介
image.png

软键盘一共四个不同界面,通过上面的功能键进行切换。

目前还不支持中文输入。

Graphics类简介
如果用户比较喜欢重载OnPaint用Graphics类进行编程,那么和在windows或wince编程中的体验完全一样。不仅如此Graphics类还扩展了一些函数,比如支持图片透明、渐变、圆角矩形绘制等等方法。

Graphics类的声明如下:

    public sealed class Graphics : Microsoft.SPOT.DispatcherObject, IDisposable

    {

        public bool EmptyClipRect;

 

        publicGraphics(Bitmap bmp);

        publicGraphics(int width, intheight);

 

        public Bitmap Bitmap { get;}

        public Rectangle Clip { get;set; }

        public int Height { get; }

        public int Width { get; }

 

        public void BlendImage(Bitmapsource, int destinationX, int destinationY, intsourceX, int sourceY, intsourceWidth, int sourceHeight, ushort opacity);

        public void Clear(Colorcolor);

        public static SizeComputeTextExtent(string text, Font font);

        public static SizeComputeTextExtent(string text, Font font, intavailableWidth);

        public void Dispose();

        public void DrawEllipse(Penpen, Rectangle rect);

        public void DrawEllipse(Penpen, int x, inty, int width, intheight);

        public void DrawImage(Bitmapimage, int x, inty);

        public void DrawImage(Bitmapimage, int destinationX, int destinationY, intsourceX, int sourceY, intsourceWidth, int sourceHeight);

        public void DrawLine(Penpen, int x0, inty0, ushort Data);

        public void DrawLine(Penpen, int x0, inty0, int x1, inty1);

        public void DrawPolygon(Penpen, Point[] points);

        public void DrawPolygon(Penpen, Point[] points, bool Sealed);

        public void DrawRectangle(Penpen, Rectangle rect);

        public void DrawRectangle(Penpen, int x, inty, int width, intheight);

        public void DrawRoundRect(Penpen, Rectangle rect, int rx, int ry);

        public void DrawRoundRect(Penpen, int x, inty, int width, intheight, int rx, intry);

        public void DrawString(strings, Font font, Brushbrush, Rectangle rect);

        public void DrawString(strings, Font font, Brushbrush, int x, inty);

        public void DrawString(strings, Font font, Brushbrush, Rectangle rect, StringFormat format);

        public void FillEllipse(Brushbrush, Rectangle rect);

        public void FillEllipse(Brushbrush, int x, inty, int width, intheight);

        public void FillPolygon(Brushbrush, Point[] points);

        public void FillRectangle(Brushbrush, Rectangle rect);

        public void FillRectangle(Brushbrush, int x, inty, int width, intheight);

        public void GetTranslation(outint x, out int y);

        public void ResetClip();

        public void RotateImage(intangle, int destinationX, int destinationY, Bitmapbitmap, int sourceX, intsourceY, int sourceWidth, int sourceHeight, ushortopacity);

        public void Scale9Image(intxDst, int yDst, intwidthDst, int heightDst, Bitmap bitmap, intleftBorder, int topBorder, int rightBorder, intbottomBorder, ushort opacity);

        public void SetPixel(Colorcolor, int x, inty);

        public void StretchImage(intxDst, int yDst, intwidthDst, int heightDst, Bitmap bitmap, intxSrc, int ySrc, intwidthSrc, int heightSrc, ushort opacity);

        public void TileImage(intxDst, int yDst, Bitmapbitmap, int width, intheight, ushort opacity);

        public void Translate(intdx, int dy);

    }

界面设计简介
由于.Net Micro Framework的IDE开发环境并不支持所见即所得的窗体设计功能,所以我们可以用.Net Framework和.Net Compact Framework开发环境设计窗体,然后把相关窗体文件(如Form1.cs和Form1.designer.cs文件)直接导入到.Net Micro Framework工程中,稍加删减即可为.Net Micro Framework所用。
image.png

   

(window 控件的字体可以设置为:字体"Arial"  大小11.25F,这种字体和底层设备的字体大小比较接近 )

关于字体库
由于字体文件相对较大,所以YFSoft.Font库文件是全开源的,用户可以根据需要自行定义字体,设置好进行编译,替换系统所提供的YFSoft.Font.*文件即可。

public Font(string name, float emSize, FontStylestyle)

        {

            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字体如何定制,请参见我以前写的博文《.NetMicro Framework研究—中文显示》和《.NetMicro Framework研究—Tinyfnt字体研究》。

字体工具下载:http://www.sky-walker.com.cn/MFRelease/Tools/YFTFConvert.rar

未来发展规划
(1)、采用组态软件进行界面设计,并自动生成界面相关的代码。

(2)、再扩展几个工业用控件,比如动态曲线,表格,仪表盘显示等等。
image.png

演示视频
视频播放地址: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

相关实践学习
钉钉群中如何接收IoT温控器数据告警通知
本实验主要介绍如何将温控器设备以MQTT协议接入IoT物联网平台,通过云产品流转到函数计算FC,调用钉钉群机器人API,实时推送温湿度消息到钉钉群。
阿里云AIoT物联网开发实战
本课程将由物联网专家带你熟悉阿里云AIoT物联网领域全套云产品,7天轻松搭建基于Arduino的端到端物联网场景应用。 开始学习前,请先开通下方两个云产品,让学习更流畅: IoT物联网平台:https://iot.console.aliyun.com/ LinkWAN物联网络管理平台:https://linkwan.console.aliyun.com/service-open
相关文章
|
1月前
|
人工智能 边缘计算 监控
【开源视频联动物联网平台】视频AI智能分析部署方式
【开源视频联动物联网平台】视频AI智能分析部署方式
99 3
|
1月前
|
传感器 物联网 决策智能
Node-RED 规则引擎:开启物联网时代的智能决策
Node-RED 规则引擎:开启物联网时代的智能决策
73 0
|
1月前
|
Web App开发 监控 中间件
【开源视频联动物联网平台】视频接入网关的用法
【开源视频联动物联网平台】视频接入网关的用法
34 1
|
1月前
|
传感器 边缘计算 物联网
【开源视频联动物联网平台】为什么需要物联网网关?
【开源视频联动物联网平台】为什么需要物联网网关?
27 2
|
1月前
|
传感器 移动开发 监控
嵌入式物联网设计水稻田智能灌溉系统实现
嵌入式物联网设计水稻田智能灌溉系统实现
80 0
|
8月前
|
传感器 边缘计算 物联网
基于边缘计算的智能物联网:未来趋势与挑战
感谢您阅读本文!如果您对基于边缘计算的智能物联网、相关技术或未来发展有任何疑问或想法,请在评论区与我交流。让我们一起探索边缘计算如何为智能物联网带来更多的创新和机遇!
287 1
|
4月前
|
传感器 人工智能 自动驾驶
【Android App】物联网实战项目之自动驾驶的智能小车(附源码和演示 超详细)
【Android App】物联网实战项目之自动驾驶的智能小车(附源码和演示 超详细)
85 0
|
13天前
|
机器学习/深度学习 人工智能 算法
【智能时代的颠覆】AI打开物联网之门
【智能时代的颠覆】AI打开物联网之门
95 0
|
9月前
|
传感器 编解码 安全
智能物联网码垛机械臂设计
一、题目 智能物联网码垛机械臂设计 二、技术参数 1.机械设计,电路设计协同设计。 2.通过串口通信实现与电脑上位机的通信。 3.通过esp8266实现无线网络通信,完成对机械臂的控制。 三、设计任务及要求 1.完成机械结构设计与三维建模。 2.完成对机械臂的基础控制。
|
5月前
|
物联网 5G 定位技术
智能物联网远程应用连接系统
智能物联网远程应用连接系统
118 0

相关产品

  • 物联网平台