Share via


Writing a New .NET Micro Framework Program

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Combine your development expertise with this code to work through the process of writing an application.

Writing a .NET Micro Framework program for your device is extremely similar to writing a .NET program for a desktop computer. Not only do you you use many of the same classes, but you also have access to classes provided only in the .NET Micro Framework that are are specialized for embedded development.

Example

  1. In the Visual Studio Solution Explorer window, select the file GPIOButtonInputProvider.cs, and then press the Delete key. This deletes the file from the project, to simplify the automatically generated program.

  2. Replace the C# source code in the file Program.cs with the following code.

    using Microsoft.SPOT;
    using Microsoft.SPOT.Input;
    using Microsoft.SPOT.Presentation;
    using Microsoft.SPOT.Presentation.Controls;
    
    namespace HelloWorld
    {
        public class Program : Microsoft.SPOT.Application
        {
            // Holds the object that represents the program's main window.
            private Window mainWindow;
    
            public static void Main()
            {
                // Instantiate the application class object.
                Program myApplication = new Program();
    
                // Create the program's main window.
                Window mainWindow = myApplication.CreateWindow();
    
                // Start the application
                myApplication.Run(mainWindow);
            }
    
            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 = "Hello, World";
                text.HorizontalAlignment = 
                    Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
                text.VerticalAlignment = 
                    Microsoft.SPOT.Presentation.VerticalAlignment.Center;
    
                // Add the text control to the window.
                mainWindow.Child = text;
    
                // Set the window visibility to visible.
                mainWindow.Visibility = Visibility.Visible;
    
                // Attach the button focus to the window.
                Buttons.Focus(mainWindow);
    
                return mainWindow;
            }
        }
    }
    
  3. Press F5 to compile and run the program. "Hello, World" appears on the emulator’s display.

For more detailed information on writing programs for the .NET Micro Framework, see Writing and Building Managed C# Applications.