.Net Mirco Framework 2007技术大会

简介: 最近公司很多项目都有大量嵌入式设备使用,由于WinCE系统相对较大,对硬件平台要求过高,所以对.Net MF一直比较关注。今天总算大开眼界了

.Net Mirco Framework 2007技术大会

2006年在《程序员》杂志上通过看马宁的专栏文章,第一次知道了.Net MF。一年后的今天终于近距离地接触了.Net Mirco Frmaework,对MF有了一定的感性认识。

最近公司很多项目都有大量嵌入式设备使用,由于WinCE系统相对较大,对硬件平台要求过高,所以对.Net MF一直比较关注。今天总算大开眼界了。
image.png
微软公司的Colin Miller和Digi公司的John Leier在上午的演讲拉开了.Net MF序幕,针对嵌入式领域,一个从软件角度进行阐述,另一个从硬件平台角度进行呼应,一软一硬,二者强强联合,恐怕未来嵌入式智能设备一半以上的项目开发要被其收入囊中了。下午的中文演讲给人感觉有些干瘪,两三个演讲,平均短短十几分钟就草草收场。后来微软公司杜伟的演讲,从VS2005一行行难以看清的代码,到一个个令人惊艳的样例把MF开发技术推向最前台。
image.png
Digi公司很是有魄力,免费送出15套开发套件(5个作为回答问题的奖品,10个抽奖),自己即没有回答问题的勇气,也没有好的运气,只好剩下羡慕的份了。

最后为每个人送出的1G优盘(类似微软今年MVP大礼包中的优盘)很有分量,不仅是1G的容量,并且里面竟然把所有的幻灯片拷贝其中,更没有想到的是,MF 的SDK也在里面,真棒!

回到家迫不及待装了一份MF SDK(MicroFrameworkSDK.MSI 区区只有5998 kb,强!),有模拟器,也有示例。
image.png
其中几个示例不知道为什么编译成功,就是运行失败,对第二示例比较感兴趣,可以绘制图形,并且可以贴图。
image.png
image.png
image.png
相关代码如下:

// Copyright (C) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Shapes;

using PresentationDemo;


//////////////////////////////////////////////////////////////////////////////


public sealed class MyApp : Application {
   // This static field prevents the object from being GC'd
   private static GpioButtonInputProvider s_gpioInputProvider;

   public Font NinaBFont;
   public Font SmallFont;
   public Bitmap Snowflake;

   private MyApp() {
      // Initialize the Buttons/Pins dispatcher
      s_gpioInputProvider = new GpioButtonInputProvider(this.Dispatcher, null);

      // Load some resources
      NinaBFont = Resources.GetFont(Resources.FontResources.NinaBFont);
      SmallFont = Resources.GetFont(Resources.FontResources.SmallFont);
      Snowflake = Resources.GetBitmap(Resources.BitmapResources.Snowflake);
   }

   protected override void OnStartup(EventArgs e) {
      // Create and set the application's main window
      this.MainWindow = new MainMenuWindow(this);
      base.OnStartup(e);
   }

   public void GoHome() {
      Buttons.Focus(this.MainWindow); // Set focus back to the main window
   }

   public static void Main() {
      new MyApp().Run();   // Start the app's main window
   }
}


//////////////////////////////////////////////////////////////////////////////


// This is the base class of all our windows; it makes every window visible, 
// sets the window's size to the full size of the LCD, and give the window focus
internal class PresentationWindow : Window {
   protected MyApp m_app;

   protected PresentationWindow(MyApp app) {
      m_app = app;

      // Make the window visible and the size of the LCD
      this.Visibility = Visibility.Visible;
      this.Width = SystemMetrics.ScreenWidth;
      this.Height = SystemMetrics.ScreenHeight;
      Buttons.Focus(this); // Set focus to this window
   }

   protected override void OnButtonDown(ButtonEventArgs e) {
      // Remove this window form the Window Manager
      this.Close();

      // When any button is pressed, go back to the Home page
      m_app.GoHome();
   }
}

//////////////////////////////////////////////////////////////////////////////


internal sealed class MainMenuWindow : PresentationWindow {
   private ListBox m_listbox;

   public ListBox MainListBox { get { return m_listbox; } }

   public MainMenuWindow(MyApp app)
      : base(app) {

      Color instructionTextColor = ColorUtility.ColorFromRGB(192, 192, 192);
      Color backgroundColor = ColorUtility.ColorFromRGB(26, 118, 183);  
      Color unselectedItemColor = ColorUtility.ColorFromRGB(192, 192, 255);   // Unselected listbox item color
      Color selectedItemColor = Colors.White;                                 // Selected listbox item color

      // The Main window contains a veritcal StackPanel
      StackPanel panel = new StackPanel(Orientation.Vertical);
      this.Child = panel;

      // The top child contains text with instructions
      TextFlow textflow = new TextFlow();
      textflow.TextAlignment = TextAlignment.Center;
      textflow.Visibility = Visibility.Visible;
      textflow.TextRuns.Add(
         new TextRun(Resources.GetString(Resources.StringResources.SelectAnItemFromBelow),
         app.NinaBFont, instructionTextColor));
      panel.Children.Add(textflow);

      // Add a blank line to the stack
      panel.Children.Add(textflow = new TextFlow());
      textflow.TextRuns.Add(" ", app.NinaBFont, instructionTextColor);
      textflow.Visibility = Visibility.Visible;

      // The next child contains a listbox with options
      m_listbox = new ListBox();

      // Prepare the listbox
      Buttons.Focus(m_listbox);
      panel.Children.Add(m_listbox);
      this.Background = m_listbox.Background = new SolidColorBrush(backgroundColor);

      m_listbox.SelectionChanged += delegate(Object sender, SelectionChangedEventArgs e) {
         Int32 previousSelectedIndex = e.PreviousSelectedIndex;
         if (previousSelectedIndex != -1) {  // If there was a previous index
            // Change previously-selected listbox item color to unselected color
            ((Text)m_listbox.Items[previousSelectedIndex].Child).ForeColor = unselectedItemColor;
         }

         // Change newly-selected listbox item color to selected color
         ((Text)m_listbox.Items[e.SelectedIndex].Child).ForeColor = selectedItemColor;
      };

      // Add the items to the listbox
      foreach (String s in new String[] { "Vertical Stack", "Horizontal Stack", "Canvas", "Diagonal" }) {
         Text text = new Text(m_app.NinaBFont, s + " Panel Demo");
         text.ForeColor = unselectedItemColor;
         text.TextAlignment = TextAlignment.Center;
         text.Width = this.Width;
         ListBoxItem lbi = new ListBoxItem();
         lbi.Background = m_listbox.Background;
         lbi.Child = text;
         m_listbox.Items.Add(lbi);
      }
      m_listbox.SelectedIndex = 0;

      // Add a blank line in the stack
      panel.Children.Add(textflow = new TextFlow());
      textflow.TextRuns.Add(" ", app.NinaBFont, instructionTextColor);
      textflow.Visibility = Visibility.Visible;

      // The bottom child contains text with return instructions
      textflow = new TextFlow();
      textflow.TextAlignment = TextAlignment.Center;
      textflow.Visibility = Visibility.Visible;
      textflow.TextRuns.Add(
         new TextRun("(After viewing a Panel Demo, hit Enter to return to this screen)",
         app.NinaBFont, instructionTextColor));
      panel.Children.Add(textflow);
   }

   protected override void OnButtonDown(ButtonEventArgs e) {
      // If <Enter> button is pressed, go into the selected demo
      if (e.Button == Button.Select) {
         switch (MainListBox.SelectedIndex) {
            case 0:  // Vertical Stack Panel Demo
               new StackPanelDemo(m_app, Orientation.Vertical);
               break;
            case 1:  // Horizontal Stack Panel Demo
               new StackPanelDemo(m_app, Orientation.Horizontal);
               break;
            case 2:  // Canvas Panel Demo
               new CanvasPanelDemo(m_app);
               break;
            case 3:  // Diagonal Panel Demo
               new DiagonalPanelDemo(m_app);
               break;
         }
      }

      // Don't call base implementation (base.OnButtonDown) or we'll go back Home
   }

   protected override void OnGotFocus(FocusChangedEventArgs e) {
      // Whenever this window gets focus, it gives it to its listbox
      Buttons.Focus(m_listbox);
      base.OnGotFocus(e);
   }
}


//////////////////////////////////////////////////////////////////////////////


internal sealed class StackPanelDemo : PresentationWindow {
   // This class shows how to build your own shape drawing in a DrawingContext
   private sealed class Cross : Shape {
      public Cross() { }

      public override void OnRender(DrawingContext dc) {
         // Draw a line from top, left to bottom, right
         dc.DrawLine(base.Stroke, 0, 0, Width, Height);

         // Draw a line from top, right to bottom, left
         dc.DrawLine(base.Stroke, Width, 0, 0, Height);
      }
   }

   public StackPanelDemo(MyApp app, Orientation orientation)
      : base(app) {
      StackPanel panel = new StackPanel(orientation);
      this.Child = panel;
      panel.Visibility = Visibility.Visible;

      Shape[] shapes = new Shape[] {
         new Ellipse(),
         new Line(),
         new Polygon(new Int32[] { 0, 0,    50, 0,    50, 50,    0, 50 }), // A Square
         new Rectangle(),
         new Cross() // Our own custom shape
      };

      for (Int32 x = 0; x < shapes.Length; x++) {
         Shape s = shapes[x];
         s.Fill = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 255, 0));
         s.Stroke = new Pen(Color.Black, 2);
         s.Visibility = Visibility.Visible;
         s.HorizontalAlignment = HorizontalAlignment.Center;
         s.VerticalAlignment = VerticalAlignment.Center;
         s.Height = Height - 1;
         s.Width = Width - 1;

         if (panel.Orientation == Orientation.Horizontal)
            s.Width /= shapes.Length;
         else
            s.Height /= shapes.Length;

         panel.Children.Add(s);
      }
   }
}


//////////////////////////////////////////////////////////////////////////////


internal sealed class CanvasPanelDemo : PresentationWindow {
   public CanvasPanelDemo(MyApp app)
      : base(app) {
      Canvas canvas = new Canvas();
      this.Child = canvas;
      this.Background = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 255, 255));

      for (Int32 x = 0; x < Width; x += Width / 4) {
         for (Int32 y = 0; y < Height; y += Height / 4) {
            Text text = new Text(m_app.SmallFont, " (" + x + "," + y + ")");
            Canvas.SetLeft(text, x);
            Canvas.SetTop(text, y);
            canvas.Children.Add(text);
         }
      }
   }
}


//////////////////////////////////////////////////////////////////////////////


internal sealed class DiagonalPanelDemo : PresentationWindow {
   public DiagonalPanelDemo(MyApp app)
      : base(app) {
      DiagonalPanel panel = new DiagonalPanel();
      this.Child = panel;
      this.Background = new LinearGradientBrush(
         ColorUtility.ColorFromRGB(192, 0, 0), ColorUtility.ColorFromRGB(32, 0, 0), 0, 0, Width, Height);

      for (Int32 x = 0; x < 4; x++) {
         Bitmap b = new Bitmap(Width / 4, Height / 4);
         b.StretchImage(0, 0, app.Snowflake, b.Width, b.Height, (UInt16)((x + 1) * 50));
         Image image = new Image(b);
         panel.Children.Add(image);
      }
   }

   // This class shows how to build your own Panel
   private sealed class DiagonalPanel : Panel {
      public DiagonalPanel() {
      }

      protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) {
         // Called to calculate the width/height desired
         desiredWidth = 0;
         desiredHeight = 0;
         foreach (UIElement child in Children) {
            if (child.Visibility != Visibility.Collapsed) {
               child.Measure(Int32.MaxValue, Int32.MaxValue);
               Int32 childWidth, childHeight;
               child.GetDesiredSize(out childWidth, out childHeight);
               desiredWidth += childWidth;
               desiredHeight += childHeight;
            }
         }
      }

      protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) {
         Int32 x = 0, y = 0;
         foreach (UIElement child in Children) {
            if (child.Visibility != Visibility.Collapsed) {
               Int32 childWidth, childHeight;
               child.GetDesiredSize(out childWidth, out childHeight);
               child.Arrange(x, y, childWidth, childHeight);
               x += childWidth;
               y += childHeight;
            }
         }
      }
   }
}


//////////////////////////////////////////////////////////////////////////////

后记:此外在会上还遇到了我的偶像马宁、马琪、张欣(还是张欣强,通过回答问题获得一个MF开放套件),如果他们不介意附上照片作个留念:-)
image.png

相关文章
|
13天前
|
监控 Cloud Native 测试技术
.NET技术深度解析:现代企业级开发指南
每日激励:“不要一直责怪过去的自己,他曾经站在雾里也很迷茫”。我是蒋星熠Jaxonic,一名在代码宇宙中探索的极客旅人。从.NET Framework到.NET 8,我深耕跨平台、高性能、云原生开发,践行领域驱动设计与微服务架构,用代码书写技术诗篇。分享架构演进、性能优化与AI融合前沿,助力开发者在二进制星河中逐光前行。关注我,共探技术无限可能!
.NET技术深度解析:现代企业级开发指南
|
6月前
|
SQL 小程序 API
如何运用C#.NET技术快速开发一套掌上医院系统?
本方案基于C#.NET技术快速构建掌上医院系统,结合模块化开发理念与医院信息化需求。核心功能涵盖用户端的预约挂号、在线问诊、报告查询等,以及管理端的排班管理和数据统计。采用.NET Core Web API与uni-app实现前后端分离,支持跨平台小程序开发。数据库选用SQL Server 2012,并通过读写分离与索引优化提升性能。部署方案包括Windows Server与负载均衡设计,确保高可用性。同时针对API差异、数据库老化及高并发等问题制定应对措施,保障系统稳定运行。推荐使用Postman、Redgate等工具辅助开发,提升效率与质量。
210 0
|
10月前
|
开发框架 算法 .NET
C#/.NET/.NET Core技术前沿周刊 | 第 15 期(2024年11.25-11.30)
C#/.NET/.NET Core技术前沿周刊 | 第 15 期(2024年11.25-11.30)
143 6
|
10月前
|
开发框架 Cloud Native .NET
C#/.NET/.NET Core技术前沿周刊 | 第 16 期(2024年12.01-12.08)
C#/.NET/.NET Core技术前沿周刊 | 第 16 期(2024年12.01-12.08)
139 6
|
11月前
|
开发框架 安全 .NET
在数字化时代,.NET 技术凭借跨平台兼容性、丰富的开发工具和框架、高效的性能及强大的安全稳定性,成为软件开发的重要支柱
在数字化时代,.NET 技术凭借跨平台兼容性、丰富的开发工具和框架、高效的性能及强大的安全稳定性,成为软件开发的重要支柱。它不仅加速了应用开发进程,提升了开发质量和可靠性,还促进了创新和业务发展,培养了专业人才和技术社区,为软件开发和数字化转型做出了重要贡献。
180 5
|
11月前
|
传感器 人工智能 供应链
.NET开发技术在数字化时代的创新作用,从高效的开发环境、强大的性能表现、丰富的库和框架资源等方面揭示了其关键优势。
本文深入探讨了.NET开发技术在数字化时代的创新作用,从高效的开发环境、强大的性能表现、丰富的库和框架资源等方面揭示了其关键优势。通过企业级应用、Web应用及移动应用的创新案例,展示了.NET在各领域的广泛应用和巨大潜力。展望未来,.NET将与新兴技术深度融合,拓展跨平台开发,推动云原生应用发展,持续创新。
139 4
|
11月前
|
开发框架 .NET C#
.NET 技术凭借高效开发环境、强大框架支持及跨平台特性,在软件开发中占据重要地位
.NET 技术凭借高效开发环境、强大框架支持及跨平台特性,在软件开发中占据重要地位。从企业应用到电子商务,再到移动开发,.NET 均展现出卓越性能,助力开发者提升效率与项目质量,推动行业持续发展。
218 4
|
11月前
|
机器学习/深度学习 人工智能 Cloud Native
在数字化时代,.NET 技术凭借其跨平台兼容性、丰富的类库和工具集以及卓越的性能与效率,成为软件开发的重要平台
在数字化时代,.NET 技术凭借其跨平台兼容性、丰富的类库和工具集以及卓越的性能与效率,成为软件开发的重要平台。本文深入解析 .NET 的核心优势,探讨其在企业级应用、Web 开发及移动应用等领域的应用案例,并展望未来在人工智能、云原生等方面的发展趋势。
217 3
|
11月前
|
敏捷开发 缓存 中间件
.NET技术的高效开发模式,涵盖面向对象编程、良好架构设计及高效代码编写与管理三大关键要素
本文深入探讨了.NET技术的高效开发模式,涵盖面向对象编程、良好架构设计及高效代码编写与管理三大关键要素,并通过企业级应用和Web应用开发的实践案例,展示了如何在实际项目中应用这些模式,旨在为开发者提供有益的参考和指导。
112 3
|
11月前
|
开发框架 安全 Java
.NET技术的独特魅力与优势,涵盖高效的开发体验、强大的性能表现、高度的可扩展性及丰富的生态系统等方面,展示了其在软件开发领域的核心竞争力
本文深入探讨了.NET技术的独特魅力与优势,涵盖高效的开发体验、强大的性能表现、高度的可扩展性及丰富的生态系统等方面,展示了其在软件开发领域的核心竞争力。.NET不仅支持跨平台开发,具备出色的安全性和稳定性,还能与多种技术无缝集成,为企业级应用提供全面支持。
336 3