<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Aldens Blog</title><subtitle type="html" /><id>http://blogs.msdn.com/b/aldenl/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/aldenl/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/aldenl/atom.aspx" /><generator uri="http://telligent.com" version="5.6.50428.7875">Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><updated>2007-03-14T20:45:00Z</updated><entry><title>Fun with Buttons</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/aldenl/archive/2007/04/27/fun-with-buttons.aspx" /><id>http://blogs.msdn.com/b/aldenl/archive/2007/04/27/fun-with-buttons.aspx</id><published>2007-04-27T23:59:00Z</published><updated>2007-04-27T23:59:00Z</updated><content type="html">&lt;H1 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=5&gt;Fun with Buttons&lt;/FONT&gt;&lt;/H1&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;by James Webster, Test Manager, .NET Micro Framework&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;and Jerry Kindall, Programmer/Writer&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Many programs running on the Microsoft&lt;SUP&gt;®&lt;/SUP&gt; .NET Micro Framework get user input through General Purpose Input/Output (GPIO)-type buttons on their respective hardware devices. The .NET Micro Framework hardware emulator provides five built-in GPIO buttons – four directional buttons and a Select button. Of course, some devices have additional buttons. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;When you press or release a button, the GPIO interface generates an interrupt. The .NET Micro Framework translates these interrupts into events called &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonUp&lt;/B&gt; and &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonDown&lt;/B&gt;. You can register your own handler to receive either or both of these events.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Microsoft Visual Studio&lt;SUP&gt;®&lt;/SUP&gt; can provide the code you need to get started handling button events when you create a new .NET Micro Framework project. To start a new project in Visual Studio, perform the following steps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"&gt;&lt;FONT face="Times New Roman"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;1&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;FONT size=3&gt;On the &lt;B style="mso-bidi-font-weight: normal"&gt;File &lt;/B&gt;menu, point to &lt;B style="mso-bidi-font-weight: normal"&gt;New&lt;/B&gt; and then click &lt;B style="mso-bidi-font-weight: normal"&gt;Project&lt;/B&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"&gt;&lt;FONT face="Times New Roman"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;2&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;FONT size=3&gt;In the New Project window, expand the Visual C# node in the Project Types pane if it is not already expanded.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"&gt;&lt;FONT face="Times New Roman"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;3&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;FONT size=3&gt;Under &lt;B style="mso-bidi-font-weight: normal"&gt;Visual C#&lt;/B&gt;, click &lt;B style="mso-bidi-font-weight: normal"&gt;Micro Framework&lt;/B&gt;. You’ll see the standard .NET Micro Framework project templates displayed in the &lt;B style="mso-bidi-font-weight: normal"&gt;Templates&lt;/B&gt; pane.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"&gt;&lt;FONT face="Times New Roman"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;4&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;FONT size=3&gt;In the &lt;B style="mso-bidi-font-weight: normal"&gt;Templates&lt;/B&gt; pane, double-click &lt;B style="mso-bidi-font-weight: normal"&gt;Window Application&lt;/B&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;This article shows you how to write code that handles button events using the .NET Micro Framework. Keep in mind that you won’t always have to do all this work yourself. Many .NET Micro Framework user interface elements can handle buttons for you. For example, the &lt;B style="mso-bidi-font-weight: normal"&gt;ListBox&lt;/B&gt; class supports using the Up and Down buttons to move the selection bar through a list; you do not need to handle this task yourself. Even in this case, though, you will need to handle the Select button, so it is still important to be familiar with techniques for handling button input.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Button Mapping&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;A new MFWindowApplication project like the one you’ve just created contains an automatically generated class called &lt;B style="mso-bidi-font-weight: normal"&gt;GPIOButtonInputProvider.&lt;/B&gt; This class establishes a mapping scheme between the device’s GPIO pins and the buttons they represent. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The &lt;B style="mso-bidi-font-weight: normal"&gt;GPIOButtonInputProvider&lt;/B&gt; class works with the .NET Micro Framework emulator, which uses GPIO pins 0 through 4 for buttons. If you are running your applications on the emulator (or on a hardware device with the same button mappings), no changes are needed. If you are using a hardware device with other button mappings, you can modify the class to map the correct pins to the buttons. A recent article on this site, titled “Getting Started with Freescale i.MXS,” provides an example of adapting the &lt;B style="mso-bidi-font-weight: normal"&gt;GPIOButtonInputProvider&lt;/B&gt; class for the Freescale i.MXS platform. The same concept applies to other hardware, although the details might differ. The code in this article uses the default mappings.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Basic Button Fun&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The Program.cs file in a fresh MFWindowApplication project includes a stub event handler method, &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt;, which is called when any button is released. The stub prints the name of the pressed button in the Output window in Visual Studio. This method is where you will add your own code, probably using a &lt;B style="mso-bidi-font-weight: normal"&gt;switch&lt;/B&gt; statement to provide an action for each button, as in the following sample method:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private void OnButtonUp(object sender, ButtonEventArgs e)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;switch (e.Button) // e is the event record&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;case Button.Left:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = "Left";&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;case Button.Right:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = "Right";&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;case Button.Up:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = "Up";&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;case Button.Down:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = "Down";&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;case Button.Select:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = "Select";&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;default:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = "Button " + e.Button;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Our example handler places the name of any pressed button in the middle of the screen (where the text “Hello World!” initially appears). Try this now by replacing the stub &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt; method with the one shown here, then pressing F5 to run the project in the .NET Micro Framework emulator.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Advanced Button Fun&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The stub handler in the Window Application template responds to &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonUp&lt;/B&gt; events, which means that your code does not receive an event until the user has already released the button. This is the conventional way to handle simple button events, but in some cases, it is too late to be of any use. For example, you might want a button to repeatedly perform some action as long as it is held down. This requires code to run when the button is first pressed. The .NET Micro Framework provides a &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonDown&lt;/B&gt; event that you can use in conjunction with a timer to implement this functionality.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The &lt;B style="mso-bidi-font-weight: normal"&gt;Timer&lt;/B&gt; object in the &lt;B style="mso-bidi-font-weight: normal"&gt;System.Threading&lt;/B&gt; namespace periodically calls a method that you specify when you instantiate the timer. This callback method actually does most of the work; the &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonDown&lt;/B&gt; and &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonUp&lt;/B&gt; handlers primarily serve to instantiate and dispose of the timer. In this section, you will learn how to program the Up and Down buttons to continuously increment or decrement a counter. Additionally, the longer the buttons are held down, the faster the counter changes. You can apply similar techniques to graphical elements or controls, such as sliders.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;If you have not used timers before, you may not know that a method called by a timer runs in its own thread. For this reason, you should use the &lt;B style="mso-bidi-font-weight: normal"&gt;lock&lt;/B&gt; statement to synchronize the timer thread and the main thread whenever you are entering a critical section of code—that is, any code that touches the counter or the timer object while more than one thread might be running. You can only lock on object references, so in this example, the timer will be used for locking.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-SIZE: 12pt"&gt;Preliminary Steps&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;To get started, create a new .NET Micro Framework Window Application as before, then open the Program.cs file in the new project. Near the top of the file, with the other &lt;B style="mso-bidi-font-weight: normal"&gt;using&lt;/B&gt; directives, add the following code to facilitate easier use of the &lt;B style="mso-bidi-font-weight: normal"&gt;Timer&lt;/B&gt; class.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;using System.Threading;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Next, find the following lines in the &lt;B style="mso-bidi-font-weight: normal"&gt;CreateWindow&lt;/B&gt; class.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// Connect the button handler to all of the buttons.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;mainWindow.AddHandler(Buttons.ButtonUpEvent, &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;new ButtonEventHandler(OnButtonUp), false);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;After these lines, insert the following line to add a &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonDown&lt;/B&gt; event handler. By convention, this method is named &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonDown&lt;/B&gt;. You will add the code for this method later.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;mainWindow.AddHandler(Buttons.ButtonDownEvent, &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;new ButtonEventHandler(OnButtonDown), false);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now, somewhere in the &lt;B style="mso-bidi-font-weight: normal"&gt;Program&lt;/B&gt; class, add the following declarations. (They can be anywhere in the class as long as they are not in a method, but you might want to put them right before the stub &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt; method so they will be close to the methods that use them.) The variable &lt;B style="mso-bidi-font-weight: normal"&gt;counterValue &lt;/B&gt;is the number we will be adjusting with the buttons. The rest of these variables have to do with the timer that will provide the repeat function.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// the value to be adjusted using Up/Down buttons&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private int counterValue = 50;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// initial, minimum, and current settings for timer in milliseconds&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private const int initialInterval = 500;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private const int minimumInterval = 50;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private int currentInterval;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// the active timer&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private Timer repeatTimer = null;&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;OnButtonDown&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;With the preceding code in place, insert the following lines to add the &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonDown&lt;/B&gt; method.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// handle a button press, starting a timer for repeats&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private void OnButtonDown(object sender, ButtonEventArgs e)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HandleButtons(e);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;lock (repeatTimer)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// dispose of existing timer (in case more than one button is down)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (repeatTimer != null) repeatTimer.Dispose();&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// start the timer firing every initialInterval milliseconds&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;currentInterval = initialInterval;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (e.Button == Button.Up || e.Button == Button.Down)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;repeatTimer = new Timer(OnTimer, e, currentInterval,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;currentInterval);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The&lt;B style="mso-bidi-font-weight: normal"&gt; OnButtonDown&lt;/B&gt; method receives control whenever any button is pressed. First, it&lt;B style="mso-bidi-font-weight: normal"&gt; &lt;/B&gt;calls the &lt;B style="mso-bidi-font-weight: normal"&gt;HandleButtons&lt;/B&gt; method (passing the event record, &lt;B style="mso-bidi-font-weight: normal"&gt;e&lt;/B&gt;, so that &lt;B style="mso-bidi-font-weight: normal"&gt;HandleButtons&lt;/B&gt; knows which button was pressed and can adjust &lt;B style="mso-bidi-font-weight: normal"&gt;counterValue&lt;/B&gt; appropriately). If the Up button or Down button was pressed, this method instantiates a &lt;B style="mso-bidi-font-weight: normal"&gt;Timer&lt;/B&gt; object, specifying the &lt;B style="mso-bidi-font-weight: normal"&gt;OnTimer&lt;/B&gt; method (which we will discuss later in this article) as the callback function. Timers can pass a state object to the callback; in this example we specify the event record, &lt;B style="mso-bidi-font-weight: normal"&gt;e&lt;/B&gt;, because &lt;B style="mso-bidi-font-weight: normal"&gt;OnTimer&lt;/B&gt; needs the event record to pass to &lt;B style="mso-bidi-font-weight: normal"&gt;HandleButtons&lt;/B&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;It is possible for a user to press two or more buttons simultaneously on an actual hardware device. Although this is not possible with the emulator, you should address this possibility in your code so that the application does not behave in a way the user does not expect. If the timer already exists (as indicated by a non-null value in &lt;B style="mso-bidi-font-weight: normal"&gt;repeatTimer&lt;/B&gt;), meaning that another button is already pressed, the existing timer is disposed of before a new one is instantiated. This results in “last button wins” behavior that users will find natural.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;OnButtonUp&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonUp&lt;/B&gt; event handler, &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt;, merely disposes of the timer to stop the repeating behavior. You should replace the stub &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt; handler with the following:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// stop the repeat timer when the user releases a button&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private void OnButtonUp(object sender, ButtonEventArgs e)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;lock (repeatTimer)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// if a timer exists, dispose of it&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (repeatTimer != null) repeatTimer.Dispose();&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;repeatTimer = null;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt; method is called when any button is released, not just the Up button or the Down button, although the latter two buttons are the only ones that start the timer. Therefore, we dispose of the timer only if it actually exists (that is, if the &lt;B style="mso-bidi-font-weight: normal"&gt;repeatTimer&lt;/B&gt; reference is non-null). Otherwise, releasing the Select button, for example, would throw an exception trying to dispose of a timer that does not exist. (If a user has pressed more than one button on the device at the same time, this means that the first button that is released will stop the timer. Releasing any other buttons afterward will have no effect.) After disposing of the timer, we set &lt;B style="mso-bidi-font-weight: normal"&gt;repeatTimer&lt;/B&gt; to &lt;B style="mso-bidi-font-weight: normal"&gt;null&lt;/B&gt; to record that the timer no longer exists.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;OnTimer&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The &lt;B style="mso-bidi-font-weight: normal"&gt;OnTimer&lt;/B&gt; method, which follows, is called periodically by the timer, initially every 500 milliseconds (every half second).&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// called by the timer to repeat a button action&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private void OnTimer(Object e)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HandleButtons(e);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;lock (repeatTimer)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// decrease timer interval for the next repeat&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (currentInterval &amp;gt; minimumInterval)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;currentInterval -= 50;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (currentInterval &amp;lt; minimumInterval) &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;currentInterval = minimumInterval;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;repeatTimer.Change(currentInterval, currentInterval);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The first thing &lt;B style="mso-bidi-font-weight: normal"&gt;OnTimer&lt;/B&gt; does is call &lt;B style="mso-bidi-font-weight: normal"&gt;HandleButtons&lt;/B&gt; to make sure that the counter gets updated appropriately for the button being held. Then the timer interval is reduced so that the repeated increment or decrement action goes faster (up to a prescribed limit) the longer the button is held down.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;HandleButtons&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The&lt;B style="mso-bidi-font-weight: normal"&gt; HandleButtons&lt;/B&gt; method is the last method needed for our press-and-hold functionality. It contains a &lt;B style="mso-bidi-font-weight: normal"&gt;switch&lt;/B&gt; statement much like the one you saw in the “Basic Button Fun” section earlier in this article. Because &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonDown&lt;/B&gt; and &lt;B style="mso-bidi-font-weight: normal"&gt;OnTimer&lt;/B&gt; both need this functionality to process button actions, the necessary code has been “broken out” into &lt;B style="mso-bidi-font-weight: normal"&gt;HandleButtons&lt;/B&gt;, as follows:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; tab-stops: 298.5pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;// button handler called from OnButtonDown and by timer&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;private void HandleButtons(Object e)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;lock (repeatTimer)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;switch (((ButtonEventArgs)e).Button)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;case Button.Up:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (counterValue &amp;lt; 99) counterValue++;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;case Button.Down:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;if (counterValue &amp;gt; 0) counterValue--;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;case Button.Select:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;counterValue = 50;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;break;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Lucida Console"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;// display the new value of the counter on the screen&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((Text)mainWindow.Child).TextContent = counterValue.ToString();&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;mainWindow.Child.Invalidate();&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The only slightly tricky aspect of the &lt;B style="mso-bidi-font-weight: normal"&gt;HandleButtons&lt;/B&gt; method is the cast of the event record, &lt;B style="mso-bidi-font-weight: normal"&gt;e&lt;/B&gt;, to type &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonEventArgs&lt;/B&gt;, which is necessary because the method is used as a callback function for a timer, which can pass any object reference. Note also that we need to invalidate the text object to force it to be redrawn immediately. The rest of the code should be familiar to you by now.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;Trying It Out&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;After making the preceding changes to Program.cs, save it and run it in the .NET Micro Framework emulator by pressing &lt;B style="mso-bidi-font-weight: normal"&gt;F5&lt;/B&gt;. Hold the emulator’s Up button and observe how the displayed value changes slowly at first, but then changes faster and faster as you continue to hold the button down. Also notice how you can easily make fine adjustments by pressing and releasing the buttons quickly. This behavior comes for “free”—as long as you release the button before the initial timer interval, it acts much like it would have if you had programmed only a &lt;B style="mso-bidi-font-weight: normal"&gt;ButtonUp&lt;/B&gt; handler. Behind the scenes, of course, a timer is being instantiated by &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonDown&lt;/B&gt;, then disposed of by &lt;B style="mso-bidi-font-weight: normal"&gt;OnButtonUp&lt;/B&gt; before it has time to activate.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The emulator screen initially displays “Hello World!” until you press the Up button, the Down button, or the Select button. This is a leftover behavior from the Window Application template. You can eliminate it by opening the Resources.resx file and changing the value of &lt;B style="mso-bidi-font-weight: normal"&gt;String1&lt;/B&gt; to 50, the initial value of the counter, as in the following illustration.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;&lt;v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;&lt;v:formulas&gt;&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;&lt;/v:formulas&gt;&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;&lt;o:lock v:ext="edit" aspectratio="t"&gt;&lt;/o:lock&gt;&lt;/v:shapetype&gt;&lt;v:shape id=_x0000_i1025 style="WIDTH: 468pt; HEIGHT: 47.25pt" type="#_x0000_t75"&gt;&lt;v:imagedata o:title="" src="file:///C:\DOCUME~1\Aldenl\LOCALS~1\Temp\msohtml1\01\clip_image001.png" mce_src="file:///C:\DOCUME~1\Aldenl\LOCALS~1\Temp\msohtml1\01\clip_image001.png"&gt;&lt;FONT face="Times New Roman" size=3&gt;&lt;/FONT&gt;&lt;/v:imagedata&gt;&lt;/v:shape&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;As an exercise, you might add functionality for the Left and Right buttons. Perhaps the Left button could set the counter to 0 and the Right button could set it to 99, providing easier access to the top and bottom of the counter’s range. This requires adding just a few lines of code to one method. A more ambitious addition would be to give the Left and Right buttons repeat functionality as well, perhaps having them add or subtract 5 from the counter.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;BR&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;FONT face="Times New Roman" size=3&gt;Copyright © 2007 Microsoft Corporation. All rights reserved. This article was originally published on &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/aldenl/default.aspx" mce_href="http://blogs.msdn.com/aldenl/default.aspx"&gt;&lt;FONT face="Times New Roman" size=3&gt;MSDN Blogs&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/I&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2303396" width="1" height="1"&gt;</content><author><name>Aldenl</name><uri>http://blogs.msdn.com/Aldenl/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Getting Started with Freescale i.MXS</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/aldenl/archive/2007/04/09/getting-started-with-freescale-i-mxs.aspx" /><id>http://blogs.msdn.com/b/aldenl/archive/2007/04/09/getting-started-with-freescale-i-mxs.aspx</id><published>2007-04-09T20:20:00Z</published><updated>2007-04-09T20:20:00Z</updated><content type="html">&lt;H1 style="MARGIN: 12pt 0in 3pt"&gt;&lt;FONT size=5&gt;Getting Started with Freescale i.MXS&lt;/FONT&gt;&lt;/H1&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The Freescale i.MXS applications processor is a low-cost ARM-based platform for deploying software solutions developed with the Microsoft&lt;SUP&gt;®&lt;/SUP&gt; .NET Micro Framework. To develop applications for i.MXS, you need the i.MXS Development Kit, which is available from Freescale. In particular, the i.MXS USB device driver included in the i.MXS Development Kit must be installed on your computer before you can deploy applications to your i.MXS device. The Development Kit also includes a wealth of other information, including schematics, sample code, and a hardware emulator.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: none; mso-list-ins: 'Jerry Kindall' 20070402T1403"&gt;&lt;FONT face="Times New Roman" size=3&gt;You can download the i.MXS Development Kit from the following location on the Freescale Web site: &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: Calibri"&gt;&lt;A title=http://www.freescale.com/files/32bit/doc/support_info/iMXS_DevKit_CD_Contents.zip href="http://www.freescale.com/files/32bit/doc/support_info/iMXS_DevKit_CD_Contents.zip" mce_href="http://www.freescale.com/files/32bit/doc/support_info/iMXS_DevKit_CD_Contents.zip"&gt;&lt;SPAN style="TEXT-DECORATION: none; text-underline: none"&gt;http://www.freescale.com/files/32bit/doc/support_info/iMXS_DevKit_CD_Contents.zip&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;You may want to run the samples included with the .NET Micro Framework on the i.MXS hardware to see how they behave and to better understand how to run your own applications on the platform. To do this, you must make some minor changes to the samples.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;There are two key differences between the i.MXS hardware and the .NET Micro Framework emulator:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;The i.MXS buttons are mapped to different General Purpose Input/Output (GPIO) pins than the emulator’s buttons. Thus, the i.MXS buttons will not be recognized when the samples are run.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;UL style="MARGIN-TOP: 0in" type=disc&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;The i.MXS buttons use a different resistor mode than the emulator’s do. This will cause the samples to throw an exception when you press an i.MXS button.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The following section of this article discusses the simple changes you need to make before you can run the Presentation sample solution on the i.MXS Development Kit hardware. For ease of development and testing, you can use conditional compilation so that your solution can be run either on the .NET Micro Framework emulator or on the i.MXS hardware. You can make similar changes to the other .NET Micro Framework samples and to your own code. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The last part of this article explains how to deploy solutions to the i.MXS device for testing. If you have previously deployed software to other platforms by means of USB, you are already familiar with the steps you’ll be using for your i.XMS deployments.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Changing the Code&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Start by opening the Presentation sample solution, following these steps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;1&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;On the &lt;B style="mso-bidi-font-weight: normal"&gt;Start&lt;/B&gt; menu, point to &lt;B style="mso-bidi-font-weight: normal"&gt;All Programs&lt;/B&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;2&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Point to &lt;B style="mso-bidi-font-weight: normal"&gt;Microsoft .NET Micro Framework&lt;/B&gt;, then click &lt;B style="mso-bidi-font-weight: normal"&gt;Samples&lt;/B&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;3&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Double-click the &lt;B style="mso-bidi-font-weight: normal"&gt;Presentation&lt;/B&gt; folder.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo2; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;4&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Double-click the &lt;B style="mso-bidi-font-weight: normal"&gt;Presentation&lt;/B&gt; solution icon.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;With the Presentation solution open, you can now edit the &lt;SPAN class=TT&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;GPIOButtInputProvider.cs&lt;/SPAN&gt;&lt;/SPAN&gt; file.&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;Button Mapping&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The i.MXS hardware uses GPIO pins numbered in the 40s for its button interface, whereas the .NET Micro Framework emulator uses pins 0 through 4. An added wrinkle is that the .NET Micro Framework &lt;SPAN class=TT&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;Cpu.Pin&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt; enumeration includes only pins 0 through 15, which means that there is no pin named &lt;SPAN class=TT&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;Cpu.Pin.GPIO_Pin40&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt; (pin 40 is the &lt;B style="mso-bidi-font-weight: normal"&gt;Select&lt;/B&gt; button on the i.MXS hardware). Thus, you must represent the i.MXS pin numbers as integers in your C++ code, using the &lt;/FONT&gt;&lt;SPAN class=TT&gt;&lt;SPAN style="FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt"&gt;&lt;FONT face="Lucida Console"&gt;(Cpu.Pin)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt; type casting syntax. In code, then, you would represent the i.MXS &lt;B style="mso-bidi-font-weight: normal"&gt;Select&lt;/B&gt; button as &lt;/FONT&gt;&lt;SPAN class=TT&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face="Lucida Console"&gt;(Cpu.Pin)40&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;To address the issue of the mapping between buttons and GPIO pins, first define a symbol to be used for the conditional code section. At the beginning of the file, add the following two lines of code:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;// comment out next line when running on the emulator&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;#define RUN_ON_IMXS_HARDWARE&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Next, update the GPIO mapping for the buttons by editing the &lt;SPAN class=TT&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;ButtonPinMap&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt; class. The following lines are the code that needs changing:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;// associate the buttons to the pins as setup in the emulator/hardware&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;m_buttonToPin[(Int32)Button.Select] = Cpu.Pin.GPIO_Pin3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;m_buttonToPin[(Int32)Button.Up] = Cpu.Pin.GPIO_Pin2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;m_buttonToPin[(Int32)Button.Down] = Cpu.Pin.GPIO_Pin4;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;m_buttonToPin[(Int32)Button.Left] = Cpu.Pin.GPIO_Pin0;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;m_buttonToPin[(Int32)Button.Right] = Cpu.Pin.GPIO_Pin1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Change this section of code to read as follows (the bold lines are the added code):&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;// associate the buttons to the pins as setup in the emulator/hardware&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;#if RUN_ON_IMXS_HARDWARE&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Select] = (Cpu.Pin)40;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Up] = (Cpu.Pin)43;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Down] = (Cpu.Pin)42;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Left] = (Cpu.Pin)48;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Right] = (Cpu.Pin)44;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;#else&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Select] = Cpu.Pin.GPIO_Pin3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Up] = Cpu.Pin.GPIO_Pin2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Down] = Cpu.Pin.GPIO_Pin4;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Left] = Cpu.Pin.GPIO_Pin0;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m_buttonToPin[(Int32)Button.Right] = Cpu.Pin.GPIO_Pin1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face="Lucida Console"&gt;#endif&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 12pt 0in 3pt"&gt;Resistor Mode&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;The sample code uses the &lt;SPAN class=TT&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;PullDown&lt;/SPAN&gt;&lt;/SPAN&gt; resistor mode. However, the i.MXS reference platform requires the &lt;SPAN class=TT&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;PullUp&lt;/SPAN&gt;&lt;/SPAN&gt; mode because the hardware does not have pull-down resistors. If you try to use the &lt;SPAN class=TT&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;PullDown&lt;/SPAN&gt;&lt;/SPAN&gt; mode, an exception occurs when you press any of the i.MXS buttons.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Conveniently, the .NET Micro Framework emulator works correctly with either resistor mode, so you can just change the mode to &lt;SPAN class=TT&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'; mso-ansi-font-size: 12.0pt"&gt;PullUp&lt;/SPAN&gt;&lt;/SPAN&gt;. Conditional code is not needed in this case.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;In the sample solution, locate the &lt;/FONT&gt;&lt;SPAN class=TT&gt;&lt;SPAN style="FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt"&gt;&lt;FONT face="Lucida Console"&gt;GpioButtonInputProvider&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt; constructor, and then change &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'"&gt;PullDown&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt; to &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'; mso-bidi-font-family: 'Courier New'"&gt;PullUp&lt;/SPAN&gt;&lt;FONT face="Times New Roman" size=3&gt;, as shown in the following examples.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Before editing:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;InterruptPort port = new InterruptPort(pin, true,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Lucida Console"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Port.ResistorMode.&lt;B style="mso-bidi-font-weight: normal"&gt;PullDown&lt;/B&gt;,&lt;SPAN style="FONT-SIZE: 7pt; mso-bidi-font-size: 12.0pt"&gt; &lt;/SPAN&gt;Port.InterruptMode.InterruptEdgeBoth);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;&lt;U&gt;After editing&lt;/U&gt;:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;InterruptPort port = new InterruptPort(pin, true,&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Code style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;&lt;FONT face="Lucida Console"&gt;Port.ResistorMode.&lt;B style="mso-bidi-font-weight: normal"&gt;PullUp&lt;/B&gt;, Port.InterruptMode.InterruptEdgeBoth);&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;These are the only code changes required for the Presentation solution.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Deploying a Solution&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Deploying a software solution to the i.MXS hardware is even simpler than making the code changes. First, click &lt;B style="mso-bidi-font-weight: normal"&gt;Configuration Manager&lt;/B&gt; on the &lt;B style="mso-bidi-font-weight: normal"&gt;Build&lt;/B&gt; menu. Then make sure that the check box under &lt;B style="mso-bidi-font-weight: normal"&gt;Deploy&lt;/B&gt; is selected in the &lt;B style="mso-bidi-font-weight: normal"&gt;Configuration Manager&lt;/B&gt; dialog box, as shown in the following illustration.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;&lt;v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&gt;&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;&lt;v:formulas&gt;&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;&lt;/v:formulas&gt;&lt;v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;&lt;o:lock aspectratio="t" v:ext="edit"&gt;&lt;A href="http://blogs.msdn.com/photos/aldenl/picture2062327.aspx"&gt;http://blogs.msdn.com/photos/aldenl/picture2062327.aspx&lt;/A&gt;&lt;/o:lock&gt;&lt;/v:shapetype&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now edit the solution’s properties to run it on the i.MXS hardware, following these steps. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;1&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;On the &lt;B style="mso-bidi-font-weight: normal"&gt;Build&lt;/B&gt; menu, click &lt;B style="mso-bidi-font-weight: normal"&gt;Presentation Properties&lt;/B&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;2&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Click the &lt;B style="mso-bidi-font-weight: normal"&gt;Micro Framework&lt;/B&gt; tab. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;3&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Under &lt;B style="mso-bidi-font-weight: normal"&gt;Deployment&lt;/B&gt;, select &lt;B style="mso-bidi-font-weight: normal"&gt;USB&lt;/B&gt; in the &lt;B style="mso-bidi-font-weight: normal"&gt;Transport&lt;/B&gt; box.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 39pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list 39.0pt"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;4&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;In the &lt;B style="mso-bidi-font-weight: normal"&gt;Device&lt;/B&gt; box, select the connected i.MXS device, as shown in the following screen shot.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;A href="http://blogs.msdn.com/photos/aldenl/picture2062339.aspx"&gt;http://blogs.msdn.com/photos/aldenl/picture2062339.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;If there are no i.MXS devices displayed in the &lt;B style="mso-bidi-font-weight: normal"&gt;Device&lt;/B&gt; box after you select &lt;B style="mso-bidi-font-weight: normal"&gt;USB&lt;/B&gt; in the &lt;B style="mso-bidi-font-weight: normal"&gt;Transport&lt;/B&gt; box, this usually means that the USB device driver is not installed on your computer. If you are sure that it is installed, check your USB connections.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Finally, click &lt;B style="mso-bidi-font-weight: normal"&gt;Deploy Solution&lt;/B&gt; on the &lt;B style="mso-bidi-font-weight: normal"&gt;Build&lt;/B&gt; menu to download your code to the i.MXS device.&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 12pt 0in 3pt"&gt;&lt;SPAN style="FONT-STYLE: normal; mso-bidi-font-style: italic"&gt;Conclusion&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Developing .NET Micro Framework solutions for the i.MXS platform is much like developing applications for other supported platforms. While some code changes are needed, they are few and minor. Using conditional compilation, you can make one version of the solution that works with both the i.MXS hardware and the .NET Micro Framework emulator. Why not download the i.MXS Development Kit today and try this for yourself?&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2062317" width="1" height="1"&gt;</content><author><name>Aldenl</name><uri>http://blogs.msdn.com/Aldenl/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Using Fonts in the Microsoft .NET Micro Framework</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/aldenl/archive/2007/03/14/using-fonts-in-the-microsoft-net-micro-framework.aspx" /><id>http://blogs.msdn.com/b/aldenl/archive/2007/03/14/using-fonts-in-the-microsoft-net-micro-framework.aspx</id><published>2007-03-14T22:45:00Z</published><updated>2007-03-14T22:45:00Z</updated><content type="html">&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;This is a short primer on how to use fonts in the Microsoft&lt;SUP&gt;®&lt;/SUP&gt; .NET Micro Framework. In this article, I’ll show you how to add a font to a project that can be used in the Windows&lt;SUP&gt;®&lt;/SUP&gt; Presentation Foundation (WPF), which is a desktop application development framework.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;First you’ll need to create a new .NET Micro Framework project in Microsoft Visual Studio&lt;SUP&gt;®&lt;/SUP&gt;, using the following steps:&lt;/FONT&gt;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in" type=1&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;On the &lt;B style="mso-bidi-font-weight: normal"&gt;File&lt;/B&gt; menu, point to &lt;B style="mso-bidi-font-weight: normal"&gt;New&lt;/B&gt; and then click &lt;B style="mso-bidi-font-weight: normal"&gt;Project&lt;/B&gt;.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;Under &lt;B style="mso-bidi-font-weight: normal"&gt;Project types&lt;/B&gt;, expand the &lt;B style="mso-bidi-font-weight: normal"&gt;Visual C#&lt;/B&gt; node, and then click &lt;B style="mso-bidi-font-weight: normal"&gt;Micro Framework&lt;/B&gt;.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;FONT face="Times New Roman" size=3&gt;Under &lt;B style="mso-bidi-font-weight: normal"&gt;Templates&lt;/B&gt;, click &lt;B style="mso-bidi-font-weight: normal"&gt;Window Application&lt;/B&gt; and then click &lt;B style="mso-bidi-font-weight: normal"&gt;OK&lt;/B&gt;.&lt;/FONT&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;FONT face="Times New Roman" size=3&gt;Now let’s add a font to our new project. You’ll notice that under the &lt;B style="mso-bidi-font-weight: normal"&gt;Resources&lt;/B&gt; node&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;in Solution Explorer there’s already a file named small.tinyfnt, as shown in the following illustration.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;U&gt;&lt;FONT color=#800080&gt;&lt;A href="http://blogs.msdn.com/photos/aldenl/images/1882313/original.aspx"&gt;http://blogs.msdn.com/photos/aldenl/images/1882313/original.aspx&lt;/A&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;A href="http://blogs.msdn.com/photos/aldenl/picture1882313.aspx"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT face="Times New Roman" size=3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Next, browse to and open the program.cs file so that we can add some text to it that uses our new font. In program.cs, change line 39 from the following:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;text.Font = &lt;SPAN style="COLOR: teal"&gt;Resources&lt;/SPAN&gt;.GetFont(&lt;SPAN style="COLOR: teal"&gt;Resources&lt;/SPAN&gt;.&lt;SPAN style="COLOR: teal"&gt;FontResources&lt;/SPAN&gt;.small);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 6pt 0in"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;to this:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;text.Font = &lt;SPAN style="COLOR: teal"&gt;Resources&lt;/SPAN&gt;.GetFont(&lt;SPAN style="COLOR: teal"&gt;Resources&lt;/SPAN&gt;.&lt;SPAN style="COLOR: teal"&gt;FontResources&lt;/SPAN&gt;.NinaB);&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Behind the scenes, the .NET Micro Framework uses an index number to search for resources in the system. This is unlike the .NET Framework on the desktop, where you can use strings to search for resources. For example, the desktop accesses fonts by using the following code:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: teal; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;Font&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt; ft = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: teal"&gt;Font&lt;/SPAN&gt;(&lt;SPAN style="COLOR: maroon"&gt;"Arial"&lt;/SPAN&gt;, 30);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;What’s important here is that the .NET Micro Framework reduced the code size by using an index number rather than by using a bulky string for each resource and by removing the ability to specify a font size. Notice that the Resources.Designer.cs file has an index number appended to the enumeration, as shown in the following code snippet:&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;internal&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt; &lt;SPAN style="COLOR: blue"&gt;enum&lt;/SPAN&gt; &lt;SPAN style="COLOR: teal"&gt;FontResources&lt;/SPAN&gt; : &lt;SPAN style="COLOR: blue"&gt;short&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;small = 13070,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;NinaB = 18060,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Sans'; mso-no-proof: yes"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;As you can see, this enumeration is what was used in the earlier Resources.GetFont() call to access the resource.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;The other basic difference between the two frameworks is that with the desktop, you can define the size of the fonts you use, whereas with the .NET Micro Framework, fonts have a predetermined size and are displayed only in that size.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;These .tinyfnt files are a new font format used by the .NET Micro Framework. The .NET Micro Framework SDK contains additional prebuilt .tinyfnt files, so now we’ll go ahead and add a reference to one of the other .tinyfnt files, using the following steps:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;1.&amp;nbsp; Double-click &lt;B style="mso-bidi-font-weight: normal"&gt;Resources.resx&lt;/B&gt; in Solution Explorer. &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;2.&amp;nbsp; On the &lt;B style="mso-bidi-font-weight: normal"&gt;Resources.resx&lt;/B&gt; tab, click the down arrow to the right of &lt;B style="mso-bidi-font-weight: normal"&gt;Add Resources&lt;/B&gt;, and then click &lt;B style="mso-bidi-font-weight: normal"&gt;Add Existing File&lt;/B&gt; on the drop-down menu, as shown in the following illustration.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;&lt;A href="http://blogs.msdn.com/photos/aldenl/images/1882317/original.aspx"&gt;http://blogs.msdn.com/photos/aldenl/images/1882317/original.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;3. In the &lt;B style="mso-bidi-font-weight: normal"&gt;Add existing file to resources&lt;/B&gt; dialog box, select &lt;B style="mso-bidi-font-weight: normal"&gt;All Files&lt;/B&gt; in the &lt;B style="mso-bidi-font-weight: normal"&gt;Files of type&lt;/B&gt; box.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;4.&amp;nbsp;While still in the dialog box, browse to \\Program Files\Microsoft .NET Micro Framework\vX.X.XXXX\Fonts, where X.X.XXXX is the version number of your .NET Micro Framework SDK.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;5.&amp;nbsp; In the Fonts folder, double-click the file NinaB.tinyfnt.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;6.&amp;nbsp; Finally, build the solution by clicking &lt;B style="mso-bidi-font-weight: normal"&gt;Rebuilt Solution&lt;/B&gt; on the &lt;B style="mso-bidi-font-weight: normal"&gt;Build&lt;/B&gt; menu.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;And that’s all there is to it. You now have another font you can use in your .NET Micro Framework projects.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;Note:&lt;/B&gt; There are only two .tinyfnt files currently available in the .NET Micro Framework, and at present there’s no way to create or add custom fonts.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This is something that is being considered for the next release of the framework.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1882337" width="1" height="1"&gt;</content><author><name>Aldenl</name><uri>http://blogs.msdn.com/Aldenl/ProfileUrlRedirect.ashx</uri></author></entry></feed>