NumericUpDown Control and Selecting Text (Revisited)#

Back in Jan '06 I wrote an post on selecting the text of a NumericUpDown control.  Peter Morris pinged me the other day to let me know that he has updated the code provided and added support for Validation events.  It's great to see code being used by others and even greater to see when people like Peter share their changes back with the community.  Check out his updates here.

If you have used any code I've released via my blog, our Open Source products or any code from OpenNETCF partners either in production or just for a hobby project let me know and I can share your story!


Wednesday, July 23, 2008 11:53:37 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  | 

 

Using Extension Methods in .NET CF 2.0#

Extension methods are a great addition to the C# 3.0 Language Specification as it allows you to extend a class by adding new methods and extend the class with features you desire.  For the .NET Compact Framework developer this is available in Visual Studio 2008 and .NET Compact Framework 3.5

At OpenNETCF we have a few developer products but are still using .NETCF 2.0.  Even a lot of our consulting jobs still use .NETCF 2.0 (and sometimes 1.0) but more customers are now wanting CF3.5.

Getting used to extension methods and then not being able to use them in pre .NETCF3.5 projects is not fun.  After doing a little search I found this were Daniel explains using extension methods in .NET 2.0 and how the compiler "figures things out". Basically the same thing applies for .NETCF 2.0.  You do require Visual Studio 2008 for this to work.

Basically what you have to do is add the following to your project:

namespace System.Runtime.CompilerServices
{
    public class ExtensionAttribute : Attribute
    {
    }
}

With that you can share extension methods you have written for .NETCF3.5 projects with .NETCF2.0 projects.

For example, I do a lot of custom drawing for controls on Windows Mobile and draw images with transparency.  Pre extension methods I would use something like this in .NETCF 2.0:

protected override void OnPaint(PaintEventArgs e)
{
    Bitmap image = new Bitmap(m_imagePath);
    ImageAttributes imageAtt = new ImageAttributes();
    Color transparentColor = image.GetPixel(0, 0);
    imageAtt.SetColorKey(transparentColor, transparentColor);
    e.Graphics.DrawImage(image, 
        new Rectangle(0,0,image.Width,image.Height), 
        0, 0, 
        image.Width, image.Height, 
        GraphicsUnit.Pixel, imageAtt);
    image.Dispose();
}

With the Attribute workaround above we create an extension method as follows:

public static void DrawImageTransparent(this Graphics graphics, 
    Bitmap image, 
    Rectangle destinationRect)
{
    ImageAttributes imageAtt = new ImageAttributes();
    Color transparentColor = image.GetPixel(0, 0);
    imageAtt.SetColorKey(transparentColor, transparentColor);
    graphics.DrawImage(image, 
        destinationRect, 0, 0, 
        image.Width, image.Height, 
        GraphicsUnit.Pixel, imageAtt);
}

And we can call it from our OnPaint method as follows:

using (Bitmap image = new Bitmap(m_imagePath))
    e.Graphics.DrawImageTransparent(image, new Rectangle(0, 0, image.Width, image.Height));

In the end we get a lot cleaner code and the extension method is portable to .NETCF3.5 and 2.0.


Wednesday, July 23, 2008 11:18:32 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  | 

 

Exchange, WCF, Windows Mobile and .NET CF#

From my recent DevTeach and EnergizeIT sessions I got a lot of interest in WCF Store and Forward feature in .NET CF 3.5 and I promised to put together a white paper on the topic. 

I just finished an article on Exchanging Data using Windows Mobile, Windows Communication Foundation, .NET Compact Framework and Exchange 2007 and posted it on our Community site.  It basically goes through some of the technical details with getting WCF and Exchange working using two sample applications, a Dispatch Sample and a Photo Sharing Sample.


Monday, June 09, 2008 12:05:12 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  | 

 

Windows Mobile 6.1 Welcome Center and Compact Framework#

For those not familiar, Windows Mobile 6.1 comes with a new application called Welcome Center which basically is a help system for users. 

WelcomeCenter

I was running some hopper tests on Task Manager 2.0 and looking through the hopper.log file I noticed the following line:

STATS: \Windows\welcomecenter.exe -> #NETCF_AGL_PARK_\Windows\welcomecenter.exe: Time in State =          0 secs ( 0.0%); Actions =      2; Visits =      2; Last visit =    196 actions ago

If you noticed #NETCF_AGL_PARK_ then you know that this means the application WelcomeCenter.exe uses Compact Framework and this is a welcoming surprise.  Let's hope this trend continues with other apps from the Windows Mobile team and other teams within Microsoft!

As for Task Manager 2.0 here is a screen shot of the new version.

image

And yes we do know that Windows Mobile 6.1 has a Task Manager included but ours does not filter out any processes or applications, allows you to terminate processes, end applications, terminate threads, change thread priorities and view all threads and modules loaded for a process.  The same binary also works on different platforms such as Windows CE, Pocket PC 2003, Windows Mobile 5 and Windows Mobile 6. It's also written using Compact Framework  and leverages the Smart Device Framework.


Wednesday, May 21, 2008 9:47:47 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  | 

 

GDI+ on Windows Mobile#

Every wanted to get GDI+ functionality on Windows Mobile?  Well Alex has just finished a new article for the community site on using GDI+ on Windows Mobile devices.  Here are a few images on what can be done:

Different Brush Styles

Different Pen Styles

GDI+ with Ink Capture


Wednesday, October 31, 2007 11:16:40 AM (Eastern Standard Time, UTC-05:00) #    Comments [0]  | 

 

All content © 2008, Mark Arteaga
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts