Compact Framework Remote Performance Monitoring

I’ve been asked by a client to help them setup Remote Performance Monitoring (RPM) tool available with .NET Compact Framework 2.0.  Although it’s pretty easy to setup, information is scattered in a lot of places so the reason for this post.

RPM can be found under %Program Files%\Microsoft.NET\SDK\CompactFramework\v2.0\bin. It is available with NETCF SP1 which can be downloaded here.

Steven Pratschner has details on setting up RPM and some other details not documented anywhere.  He’s also written some relevant articles here and here.

Chris Tacke wrote a bootstrap application that will automatically setup the device to be used with RPM.  See here for more info and to download. 

David Kline has written detailed descriptions of all the counters here.

If there is anything I missed let me know.

TabControl, TabPage, Screen Rotation and Compact Framework

Was taking a look at a screen rotation (portrait to landscape and back) issue we were having in one of our soon to be released products when using the TabControl/TabPage.Height property and Compact Framework 2.0 and Windows Mobile 5.0.

When the screen orientation changed, the Form.Resize event is raised.  Great, easy enough to adjust some ListViews that are in the TabPage using the following code:

listView2.Height = listView1.Height = (tabControl1.TabPages[0].Height / 2) 2;

Although you think it would work, it doesn’t because the TabPages[0].Height property is the Height before the Screen rotation occurs.

To work around this is easy enough, just use the Form.Height properties.

listView1.Height = listView2.Height = (this.Height (20 * m_scale)) / 2;


  • 20 is the height of the tabs
  • m_scale is to support hi res devices

Download the sample code here.

UPDATE: Got a comment here about using docking and anchoring which is true but for some reason was not working properly in our application, don’t know why so we resorted to manually calculating sizes.  I updated the sample code which shows the ListViews properly sizing using the Anchor property on rotation. 

Microsoft Windows Mobile 5.0 App Dev Course Promotion

With the recent release of Collection 5150: Developing Microsoft® Windows Mobile® 5.0 Applications Using Microsoft Visual Studio® 2005, Microsoft Learning and OpenNETCF are running a contest to give way five free access codes to the collection ($190 value).

Here’s how it will work:

Starting Monday Jan 8 2007 till Jan 12 (5 days total) we will monitor the following developer forums on the MSDN site:

Smart Devices General
Discussion general Smart device development aspects with Visual Studio 2005 in this forum.

.NET Compact Framework
All issues related to Compact Framework 2.0 and 1.0 runtimes.

Each day I will randomly pick a question asked by a user (make sure your email address is correct) and submit the name to Microsoft Learning. Each winner will then receive an email from Microsoft Learning containing an access code and instructions for registering for the online course.  At the end of the five days I’ll post all the winners.

That’s it! Now go out there and ask you’re questions!

Telephony Library Released

Neil talks about the new TAPI Managed Library OpenNETCF just released.  If you ever wanted to use the Telephony API  within your .NET Compact Framework application and don’t want the hassle of figuring out the P/Invokes then the Telephony Library may be for you.

Give it a try and download the evaluation version here and click here for more information on this and other products available from OpenNETCF.

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)


Custom Drawing OpenNETCF Calendar Controls

If you have been using the OpenNETCF Calendar Controls or are thinking if giving it a spin, you may have wondered how  you can customize the cells in the MonthView control.

Basically there are two events in the BaseCalendar control named DrawLabel and GetLabel. With GetLabel you just return a string that you want to display in the cell.  With DrawLabel you can custom draw the cell.  Say you want to display an alarm on a certain date (like the image below), then you would use DrawLabel. 

You can download the evaluation version of the Calendar Controls which includes a sample project. Just replace the MonthDemo.cs file in the sample application with this modified version of MonthDemo.cs.  Also, here is the alarm.bmp I use.  Just add it to the project as an embedded resource.


alarm.bmp (.39 KB)

MonthDemo.cs (2.93 KB)

Presenting at Toronto VB User Group (March 15)

I’ll be doing a presentation on .NET Compact Framework for Desktop Developers at the Toronto Visual Basic User Group (TVBug) this Wednesday (March 15 2006).  If you’re in the Toronto area and instrested in .NET CF development come out to this session.

Here is the abstract:

Are you a desktop developers looking to extend an application to a mobile device? Have you already written an application for a mobile device and want to extend your knowledge on what else is available? Whether you have never written a mobile application using .NET Compact Framework or have already used the .NET Compact Framework, this session will give you an overview of what devices you can develop for, what’s new in .NETCF 2.0, tips and tricks for mobile development and what are the major differences from the .NET Compact Framework and the full .NET Framework.

Thanks to Daniel Moth for letting me borrow the presentation title 🙂

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)