---
title: ".Net Micro Framework研究—窗体控件"
author: "mmdev"
date: "2007-11-15T18:37:00Z"
tags: []
slug: "net-micro-framework"
draft: false
lastmod: "2012-08-04T21:32:38Z"
id: 1620943
url: "https://mmdev.iteye.com/blog/1620943"
---

试验平台：.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 &lt; 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;

}

}

}

}

![](http://p.blog.csdn.net/images/p_blog_csdn_net/yefanqiu/MF071115001.jpg)

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

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