天天看點

【物聯網智能網關-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平台相同。

【物聯網智能網關-04】WinForm for .NET MF 功能一覽
軟鍵盤簡介
【物聯網智能網關-04】WinForm for .NET MF 功能一覽

軟鍵盤一共四個不同界面,通過上面的功能鍵進行切換。

目前還不支援中文輸入。

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所用。

【物聯網智能網關-04】WinForm for .NET MF 功能一覽

(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)、再擴充幾個工業用控件,比如動态曲線,表格,儀表盤顯示等等。

【物聯網智能網關-04】WinForm for .NET MF 功能一覽

示範視訊

視訊播放位址:

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

繼續閱讀