叶帆

.Net Micro Framework研究—窗体控件

0
阅读(2609)

.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(TextRun.EndOfLine);
                    txtf.TextRuns.Add(new TextRun("yefan789", Resources.GetFont(Resources.FontResources.small), Colors.Green));
                    txtf.TextRuns.Add(TextRun.EndOfLine);
                }
                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研发人员任重而道远啊!