OpenNETCF Samples Overview

We have had almost 6300 downloads of our samples for the Smart Device Framework 2.0 but I was answering a question in the newsgroups one day and wanted to reference the samples but couldn’t find any references to what’s included in the samples. 

Considering I put together the samples installation, I actually had to install it to remember what was installed with it! This got me thinking, if I couldn’t remember what was in it how are others supposed to know what’s in the installation especially since there is no ‘readme’ or summary anywhere.

That problem is now solved.  We have put together documentation for the samples available for the Smart Device Framework 2.0. You can download the initial document here.  We will have it up on the website in a few days.

Even if you don’t use the Smart Device Framework the samples could be useful if you are a Compact Framework Developer.

OpenNETCF.Media.WaveAudio.Wave Class

We have received a few customer request to use the Wave.SetVolume and Wave.GetVolume methods in the OpenNETCF.Media.WaveAudio.Wave class.  Unfortunately, there is no default constructor for the Wave class so you cannot directly call these methods.

Using a little bit of Reflection we can get the private contructor of the Wave class using Type.GetConstructors().

Here is some sample code to call Wave.SetVolume and Wave.GetVolume.  (NOTE:  this is currently not supported and may not work in future releases of the Smart Device Framework)

OpenNETCF.Media.WaveAudio.Wave wave = null;

ConstructorInfo[] ci = typeof(OpenNETCF.Media.WaveAudio.Wave).GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

if (ci.Length == 1)

wave = (OpenNETCF.Media.WaveAudio.Wave)ci[0].Invoke(null);

if (wave != null)


Extending OpenNETCF.Windows.Forms.Button2 class

The OpenNETCF Smart Device Framework 2.0 is currently in Beta1 and is currently released in binary form only during the beta cycle.  Even though it’s currently available only in compiled mode you can still extend the functionality of controls.  For example, I’m working on a project where I’m using the OpenNETCF.Windows.Forms.Button2 and the Image property for the button.  There are a bunch of buttons that get enabled/disbled but unfortunately when the button is disabled it still looks disabled because of the image.

To resolve the problem we can inherit from the Button2 class.  We can create a class ExtendedButton (not the name I used in the project but used it for explanation purposes).  Here is the class implementation: 

/// <summary>
/// Provides the ability for enabled and disabled images
/// </summary>
public partial class ExtendedButton : Button2
   private Image disabledImage = null;
   private Image enabledImage = null;

   public ExtendedButton()

   /// <summary>
   /// Gets or sets the disabled Image
   /// </summary>
   public Image DisabledImage
         return this.disabledImage;
         this.disabledImage = value;

   /// <summary>
   /// Gets or sets the image. Hides the base class implementation but 
   /// internally still calls the base implementation
   /// </summary>
   public new Image Image
         return base.Image;
         this.enabledImage = value;
         base.Image = this.enabledImage;

   /// <summary>
   /// Hides the System.Windows.Forms.Control.Enabled property. This is
   /// where we set the Button2.Image property depending on the enabled
   /// status.
   /// </summary>
   public new bool Enabled
         return base.Enabled;
         base.Enabled = value;
         if (base.Enabled)
            base.Image = this.enabledImage;
            base.Image = this.disabledImage;


Here is a screen shot of the sample application:

Sample application is also attached. 

Purpose of doing this is to show that you can extend controls without having the source available to you. This functionality wasn’t added to the SDF class because we are in somewhat of a code freeze for new features, but if there are enough request we can added it after the SDF2.0 release. (15.35 KB)

Drawing Rotated Text in .NET Compact Framework 2.0

Back in February of last year I posted a sample on drawing rotated text using .NET Compact Framework 1.0 and OpenNETCF Smart Device Framework 1.4.  Since then, Compact Framework 2.0 has been released and Smart Device Framework 2.0 Beta1 has also been released.  Changes in the OpenNETCF.Drawing namespace caused the existing sample to not work anymore simply because the functionality in the SDF2.0 was removed.  Why was it it removed?  With CF2.0 there is a new class within the Microsoft.WindowsCE.Forms namespace called LogFont which replaces the SDF1.4 OpenNETCF.Drawing.FontEx class. 

Some of the more trickier parts of the code are setting the proper angle.  With the OpenNETCF.Drawing.FontEx class setting the font angle was as easy as setting the Angle property.  With the LogFont class, there was no Angle property, but from reading the MSDN documentation on the class points us to the Escapement property.  To set the font at an angle of 90 degrees, you will have to set the Escapement property to 900 or (90 * 10).  The other thing to note is the FaceName property has to be a null terminated string so you have to end it withe a ‘/0’.  Below are some other properties to add more functionality to the  LogFont:

Here is an implementation of drawing rotated/angled text using the above information.  For a complete sample see the sample application. 

private void DrawTextSample()
   //For VGA support get the scale to adjust dynamically
   int scale = (int)this.Scale(this.offGfx);

   //Get the size of the current font
   SizeF size = this.offGfx.MeasureString(this.txtDraw.Text, this.Font);

   //Create a new logfont class
   Microsoft.WindowsCE.Forms.LogFont lf = new Microsoft.WindowsCE.Forms.LogFont();

   //Escapement defines the angle at which you want the text to draw
   lf.Escapement = Convert.ToInt32(this.numericUpDown1.Value)*10;
   //Set the wieght of the font
   lf.Weight = this.Weight;
   //Set the quality to draw the font
   lf.Quality = this.Quality;
   //Set the name of the font. Note the null termintion char
   lf.FaceName = this.Font.Name + “/0”;
   //Set the font height. Note that we mulitply by scale to adjust for VGA devices
   lf.Height = (int)size.Height * scale;
   //Specifies the font family
   lf.PitchAndFamily = Microsoft.WindowsCE.Forms.LogFontPitchAndFamily.Default;
   //Specify if it is strikeout
   lf.StrikeOut = Convert.ToByte(this.chkStrikeout.Checked);
   //Specify if underlined
   lf.Underline = Convert.ToByte(this.chkUnderline.Checked);
   //Create a font that is compatible with the graphics object
   Font font = Font.FromLogFont(lf);
   //Fill the background
   using(SolidBrush b = new SolidBrush(this.BackColor))
      this.offGfx.FillRectangle(b, new Rectangle(0,0,this.Width,this.Height));
   //Get the middle of the screen
   Point point = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2,
                           this.chkStrikeout.Top / 2 );
   //String format is a new class for CF2.0. Here we need to specify to not wrap the text
   //and to not clip the text if it is outside the bounds
   StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
   //Draw the text
   using (SolidBrush brush = new SolidBrush(Color.Red))
      this.offGfx.DrawString(this.txtDraw.Text, font, brush, point.X, point.Y, sf);
   //Force the screen to repaint

It’s a little more work drawing rotated/angled text using CF2.0 but the end result is the same as previous. (14.21 KB)

Known SDF 2.0 Design Time Issues

Here is a list of known issues for design time controls.  If you find more please let us know.  These will all be fixed in the next Beta release


Issue 1: When a smartlist is dropped on a form the size is 0,0

Workaround: Resize the control to a appropriate size.


Issue 2: When deleting a combobox2 from a form a coredll error is thrown

Workaround: Click OK and the combobox will be deleted from the form


Issue 3: When deleting an either an inkx or voicerecorder control it looks like the Paint of the base class gets run.  It will render on the form but you can’t select, move, delete the control and there is no variable declared for it.

Workaround: After you delete the control, save the form and close the form in designer and re-open it.  The control rendering will be gone.


Issue 4: StatusBar/StatusBarPanel still needs to be ported

Workaround: Create the control manually through code.  This will be resolved in the next release.


Issue 5: ColorDialog has no design time support

Workaround: Create the control manually through code.  We are working on this issue and hoping to have a resolution by release.



OpenNETCF Smart Device Framework 2.0 Beta 1

Smart Device Framework 2.0 Beta 1 from OpenNETCF has been released.  We have worked really hard to getting this ready and the redistributables for Beta 1 are now available.  The SDF2.0 documentation is also available online.

A lot of work was done throughout the whole SDF but some of the major changes was supporting the the new design time framework for controls for Visual Studio 2005.  Throughout the process we also decided to change some of the class names that ended with ‘Ex’ to ‘2’.  For example, OpenNETCF.Windows.Forms.ProgressBarEx is now OpenNETCF.Windows.Forms.ProgressBar2.

There are still some remaing minor issues with some controls and design time support for Visual Studio 2005.  See this post for some of those issues.

Also, check out the new Licensing Class available in the SDF 2.0.  It works the same as the full framework class so if you are looking to license your .NETCF application to your users this will help.

In a future post I will be writing some tips for creating and migrating controls for Visual Studio 2005.