Conferencia técnica de .Net Mirco Framework 2007

En 2006, aprendí sobre .Net MF por primera vez leyendo la columna de Ma Ning en la revista "Programmer". Hoy, un año después, finalmente entré en contacto con .Net Mirco Frmaework de cerca y tengo una cierta comprensión perceptiva de MF.

Recientemente, muchos proyectos de la empresa han utilizado una gran cantidad de dispositivos integrados, debido a que el sistema WinCE es relativamente grande y los requisitos de la plataforma de hardware son demasiado altos, he estado prestando más atención a .Net MF. Hoy finalmente es una revelación.

Colin Miller de Microsoft y John Leier de Digi dieron inicio a la presentación .Net MF por la mañana. Para el campo integrado, uno elaborado desde una perspectiva de software, el otro se hizo eco desde una perspectiva de plataforma de hardware, uno suave, otro duro, dos La fuerte combinación de esos, me temo que en el futuro, más de la mitad del desarrollo del proyecto de dispositivos inteligentes integrados se incluirá en la bolsa. Los discursos chinos de la tarde se sintieron un poco secos: dos o tres discursos terminaron apresuradamente en solo diez minutos en promedio. Más tarde, el discurso de Du Wei de Microsoft, desde la línea de código VS2005 que es difícil de ver, hasta muestras asombrosas una por una, llevó la tecnología de desarrollo MF a la vanguardia.

Digi es muy valiente y entregó 15 juegos de kits de desarrollo gratis (5 como premios por responder preguntas y 10 sorteos). No tuve el coraje de responder preguntas o buena suerte. No tuve más remedio que envidiar.

Finalmente, la unidad flash USB 1G (similar a la unidad flash USB en el paquete de regalo de Microsoft MVP de este año) es muy importante para todos. No solo tiene una capacidad de 1G, sino que también copia todas las diapositivas que contiene. Lo que no esperaba es que el SDK MF también sea ¡Por dentro, increíble!

No puedo esperar para instalar una copia de MF SDK cuando llegue a casa (MicroFrameworkSDK.MSI solo tiene 5998 kb, ¡fuerte!), Hay simuladores y ejemplos.

Para algunos ejemplos, no sé por qué la compilación tuvo éxito, es decir, no se ejecutó. Estoy más interesado en el segundo ejemplo. Puedes dibujar gráficos y texturas.

El código relevante es el siguiente:

// 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;

            }

         }

      }

   }

}

 

Fuente del manuscrito: Alibaba Cloud Developer Community

 

 

Supongo que te gusta

Origin blog.csdn.net/weixin_40050195/article/details/96994775
Recomendado
Clasificación