November 29, 2014
Hot Topics:

Explore the Microsoft .NET Micro Framework

  • August 13, 2008
  • By Alex Gusev
  • Send Email »
  • More Articles »

Each type may be useful for your project, and you can even create your own device emulator! The Framework is shipped with the default one, so you begin with "Hello World" Window Application and run your code on that emulator. You can always select another device and transport it (for example, USB or Serial cable) via the "Micro Framework" page in project properties:



Click here for a larger image.

Figure 3: Micro Framework Page

Your sample window application has a simple structure. It looks exactly like another application type, the Console application, but allows you to create the window (hence it is "Window" application) and contains a class to handle hardware buttons input. When you glance at the code created by the wizard, the first thing that might catch your eye is the Microsoft.SPOT namespaces:

using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;

As I said earlier, .NET Micro Framework is small but rich enough in terms of available functionality. The Object Browser snapshot can tell you more than any descriptions, although chosen names are intuitive enough:

Figure 4: .NET Micro Framework Assemblies

You should briefly walk through the code. Unlike a standard WinForms application, there are no forms here (you are in an embedded environment, after all), though it may remind you of the good old native Win32 application structure: create the window, create and register hardware input object, and finally run the 'message loop'.

The Window creation procedure gives you the opportunity to demonstrate your creativity because it constructs all the elements one by one:

public Window CreateWindow()
{
   // Create a window object and set its size to the
   // size of the display.
   mainWindow = new Window();
   mainWindow.Height = SystemMetrics.ScreenHeight;
   mainWindow.Width = SystemMetrics.ScreenWidth;

   // Create a single text control.
   Text text = new Text();

   text.Font = Resources.GetFont(Resources.FontResources.small);
   text.TextContent =
      Resources.GetString(Resources.StringResources.String1);
   text.HorizontalAlignment =
      Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
   text.VerticalAlignment =
      Microsoft.SPOT.Presentation.VerticalAlignment.Center;

   // Add the text control to the window.
   mainWindow.Child = text;

   // Connect the button handler to all of the buttons.
   mainWindow.AddHandler(Buttons.ButtonUpEvent,
      new ButtonEventHandler(OnButtonUp), false);

   // Set the window visibility to visible.
   mainWindow.Visibility = Visibility.Visible;

   // Attach the button focus to the window.
   Buttons.Focus(mainWindow);

   return mainWindow;
}

Tags: .NET



Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel