.Net Micro Framework研究—窗体控件

试验平台:.Net Micro Framework 模拟器

 

在Microsoft.SPOT.Presentation.Controls命名空间里,也就如下几个控件(姑且称为控件吧),Panel、StackPanel、Text、TextFlow、Image、ListBox、ScrollViewer 其中仅有Panel、Text、Image控件完成度相对较好,其他的实现并不完整,甚至只是一个空接口。

下面是测试代码:


  1. using System;  
  2.  
  3. using Microsoft.SPOT;  
  4.  
  5. using Microsoft.SPOT.Input;  
  6.  
  7. using Microsoft.SPOT.Presentation;  
  8.  
  9. using Microsoft.SPOT.Presentation.Controls;  
  10.  
  11. using Microsoft.SPOT.Presentation.Media;  
  12.  
  13. using Microsoft.SPOT.Presentation.Shapes;  
  14.  
  15.    
  16.  
  17. namespace MFWindow  
  18.  
  19. {  
  20.  
  21.     public class Program : Microsoft.SPOT.Application  
  22.  
  23.     {  
  24.  
  25.         public static void Main()  
  26.  
  27.         {     
  28.  
  29.             //创建窗体  
  30.  
  31.             WindowsDrawing win = new WindowsDrawing();            
  32.  
  33.             //程序运行  
  34.  
  35.             new Program().Run(win);  
  36.  
  37.         }  
  38.  
  39.           
  40.  
  41.         internal sealed class WindowsDrawing : Window  
  42.  
  43.         {  
  44.  
  45.             public  WindowsDrawing()  
  46.  
  47.             {  
  48.  
  49.                 this.Width = SystemMetrics.ScreenWidth;  
  50.  
  51.                 this.Height = SystemMetrics.ScreenHeight;  
  52.  
  53.    
  54.  
  55.                 //可设置显示方向(水平,垂直)  
  56.  
  57.                 //StackPanel panel = new StackPanel(Orientation.Vertical);  
  58.  
  59.                 StackPanel panel = new StackPanel(Orientation.Horizontal);  
  60.  
  61.                   
  62.  
  63.                 //设置对象堆叠的方式  
  64.  
  65.                 panel.HorizontalAlignment = HorizontalAlignment.Left;  
  66.  
  67.                 panel.VerticalAlignment = VerticalAlignment.Top;                             
  68.  
  69.                 this.Child = panel;  
  70.  
  71.    
  72.  
  73.                 //Text控件  
  74.  
  75.                 Text txt = new Text(Resources.GetFont(Resources.FontResources.small), "yefan");  
  76.  
  77.                 txt.Width = 100;  
  78.  
  79.                 txt.Height = 30;  
  80.  
  81.                 txt.ForeColor = Colors.Green;       
  82.  
  83.                 panel.Children.Add(txt);  
  84.  
  85.    
  86.  
  87.                 //TextFlow控件 不支持滚动条,实现还不完整  
  88.  
  89.                 TextFlow txtf = new TextFlow();  
  90.  
  91.                 txtf.ScrollingStyle = ScrollingStyle.LineByLine;  
  92.  
  93.                 txtf.TextAlignment = TextAlignment.Left;  
  94.  
  95.                 txtf.Height = 200;  
  96.  
  97.                 txtf.Width = 50;  
  98.  
  99.                
  100.  
  101.                 for (int i = 0; i < 10; i++)  
  102.  
  103.                 {  
  104.  
  105.                     txtf.TextRuns.Add(new TextRun("yefan123", Resources.GetFont(Resources.FontResources.small), Colors.Blue));  
  106.  
  107.                     //注意:换行这么写,可不是\r\n  
  108.  
  109.                     txtf.TextRuns.Add(TextRun.EndOfLine);  
  110.  
  111.                     txtf.TextRuns.Add(new TextRun("yefan456", Resources.GetFont(Resources.FontResources.small), Colors.Red));  
  112.  
  113.                     txtf.TextRuns.Add(TextRun.EndOfLine);  
  114.  
  115.                     txtf.TextRuns.Add(new TextRun("yefan789", Resources.GetFont(Resources.FontResources.small), Colors.Green));  
  116.  
  117.                     txtf.TextRuns.Add(TextRun.EndOfLine);  
  118.  
  119.                 }  
  120.  
  121.                 panel.Children.Add(txtf);           
  122.  
  123.    
  124.  
  125.                 //image  
  126.  
  127.                 Image img = new Image();  
  128.  
  129.                 img.Bitmap = Resources.GetBitmap(Resources.BitmapResources.yfmvp);  
  130.  
  131.                 panel.Children.Add(img);  
  132.  
  133.    
  134.  
  135.                 //ListBox  仅实现了一个空接口  
  136.  
  137.                 ListBox lst = new ListBox();  
  138.  
  139.                 lst.Font = Resources.GetFont(Resources.FontResources.small);  
  140.  
  141.                 lst.Items.Add(new ListBoxItem());  
  142.  
  143.                 //panel.Children.Add(lst);  
  144.  
  145.    
  146.  
  147.                 //ScrollViewer 仅实现了一个空接口  
  148.  
  149.                 ScrollViewer sv = new ScrollViewer();  
  150.  
  151.                 sv.Width = 30;  
  152.  
  153.                 sv.Height = 50;  
  154.  
  155.                 //panel.Children.Add(sv);         
  156.  
  157.                 //sv.Child = txtf;                  
  158.  
  159.             }  
  160.  
  161.         }  
  162.  
  163.     }  
  164.  
  165. }  
  166.  
  167.  
  168.  
  169.  
  170.  

目前版本的MF对TCP协议栈支持也并不完善(对串口也谈不上完善,毕竟不支持奇偶校验、停止位设置),Digi的以太网口是加入了自己的处理方案,明年二月份微软将要发布的MF V3.0版,就已经完全支持TCP了,到时候MF最理想的应用也许就是通信转换了。

 

.Net Micro Framework研究—窗体控件


从本篇内容中可以看出,微软MF之旅尚在出发点不远的地方,MF研发人员任重而道远啊!

 
















本文转自yefanqiu51CTO博客,原文链接:http://blog.51cto.com/yfsoft/323400,如需转载请自行联系原作者