天天看點

.Net Micro Framework研究—窗體控件

試驗平台:.Net Micro Framework 模拟器

在Microsoft.SPOT.Presentation.Controls命名空間裡,也就如下幾個控件(姑且稱為控件吧),Panel、StackPanel、Text、TextFlow、Image、ListBox、ScrollViewer 其中僅有Panel、Text、Image控件完成度相對較好,其他的實作并不完整,甚至隻是一個空接口。

下面是測試代碼:

using System;

using Microsoft.SPOT;

using Microsoft.SPOT.Input;

using Microsoft.SPOT.Presentation;

using Microsoft.SPOT.Presentation.Controls;

using Microsoft.SPOT.Presentation.Media;

using Microsoft.SPOT.Presentation.Shapes;

namespace MFWindow

{

    public class Program : Microsoft.SPOT.Application

    {

        public static void Main()

        {  

            //建立窗體

            WindowsDrawing win = new WindowsDrawing();         

            //程式運作

            new Program().Run(win);

        }

        internal sealed class WindowsDrawing : Window

        {

            public  WindowsDrawing()

            {

                this.Width = SystemMetrics.ScreenWidth;

                this.Height = SystemMetrics.ScreenHeight;

                //可設定顯示方向(水準,垂直)

                //StackPanel panel = new StackPanel(Orientation.Vertical);

                StackPanel panel = new StackPanel(Orientation.Horizontal);

                //設定對象堆疊的方式

                panel.HorizontalAlignment = HorizontalAlignment.Left;

                panel.VerticalAlignment = VerticalAlignment.Top;                          

                this.Child = panel;

                //Text控件

                Text txt = new Text(Resources.GetFont(Resources.FontResources.small), "yefan");

                txt.Width = 100;

                txt.Height = 30;

                txt.ForeColor = Colors.Green;    

                panel.Children.Add(txt);

                //TextFlow控件 不支援滾動條,實作還不完整

                TextFlow txtf = new TextFlow();

                txtf.ScrollingStyle = ScrollingStyle.LineByLine;

                txtf.TextAlignment = TextAlignment.Left;

                txtf.Height = 200;

                txtf.Width = 50;

                for (int i = 0; i < 10; i++)

                {

                    txtf.TextRuns.Add(new TextRun("yefan123", Resources.GetFont(Resources.FontResources.small), Colors.Blue));

                    //注意:換行這麼寫,可不是/r/n

                    txtf.TextRuns.Add(TextRun.EndOfLine);

                    txtf.TextRuns.Add(new TextRun("yefan456", Resources.GetFont(Resources.FontResources.small), Colors.Red));

                    txtf.TextRuns.Add(new TextRun("yefan789", Resources.GetFont(Resources.FontResources.small), Colors.Green));

                }

                panel.Children.Add(txtf);         

                //image

                Image img = new Image();

                img.Bitmap = Resources.GetBitmap(Resources.BitmapResources.yfmvp);

                panel.Children.Add(img);

                //ListBox  僅實作了一個空接口

                ListBox lst = new ListBox();

                lst.Font = Resources.GetFont(Resources.FontResources.small);

                lst.Items.Add(new ListBoxItem());

                //panel.Children.Add(lst);

                //ScrollViewer 僅實作了一個空接口

                ScrollViewer sv = new ScrollViewer();

                sv.Width = 30;

                sv.Height = 50;

                //panel.Children.Add(sv);      

                //sv.Child = txtf;               

            }

    }

}

目前版本的MF對TCP協定棧支援也并不完善(對序列槽也談不上完善,畢竟不支援奇偶校驗、停止位設定),Digi的以太網口是加入了自己的處理方案,明年二月份微軟将要釋出的MF V3.0版,就已經完全支援TCP了,到時候MF最理想的應用也許就是通信轉換了。

從本篇内容中可以看出,微軟MF之旅尚在出發點不遠的地方,MF研發人員任重而道遠啊!

繼續閱讀