SDF Sample: OpenNETCF.Environment2.GetFolderPath#

Problem

Scenario 1:
.NET Compact Framework provides System.Enviornment.SpecialFolder and System.Environment.GetFolderPath to get the path of any system directories.  In my application I need the ProgramFiles path but it's not available in the SpecialFolder enum.  What can the SDF do for me?

Scenario 2:
I want to use the My.Computer.FileSystem.SpecialDirectories.MyDocuments but this is not available in CF.  What can the SDF do for me?

Solution
[Tested using Windows Mobile 6 emulator and Smart Device Framework 2.1]

The Smart Device Framework provides the OpenNETCF.Environment2.GetFolderPath() and an OpenNETCF.Environment2.SpecialFolder enum.  OpenNETCF.Environment2.SpecialFolder provides more values like ProgramFiles and MyDocuments which is not provided by the Compact Framework.

Sample Use:

Scenario 1:

string programPath = OpenNETCF.Environment2.GetFolderPath(
OpenNETCF.Environment2.SpecialFolder.ProgramFiles);

Scenario 2:

string programPath = OpenNETCF.Environment2.GetFolderPath(
OpenNETCF.Environment2.SpecialFolder.MyDocuments);

 

Here are the special folders supported.

public enum SpecialFolder
{
    // Summary:
    //     The directory that contains the user's program groups.
    Programs = 2,
    //
    // Summary:
    //     The "My Documents" folder.
    MyDocuments = 5,
    //
    // Summary:
    //     The directory that serves as a common repository for documents.
    Personal = 5,
    //
    // Summary:
    //     The directory that serves as a common repository for the user's favorite
    //     items.
    Favorites = 6,
    //
    // Summary:
    //     The directory that corresponds to the user's Startup program group.  The
    //     system starts these programs whenever a user starts Windows CE.
    Startup = 7,
    //
    // Summary:
    //     The directory that contains the user's most recently used documents.
    //     Not supported in Windows Mobile.
    Recent = 8,
    //
    // Summary:
    //     The directory that contains the Start menu items.
    StartMenu = 11,
    //
    // Summary:
    //     The "My Music" folder.
    //     Supported only on Windows Mobile.
    MyMusic = 13,
    //
    // Summary:
    //     The directory used to physically store file objects on the desktop.  Do not
    //     confuse this directory with the desktop folder itself, which is a virtual
    //     folder.
    //     Not supported in Windows Mobile.
    DesktopDirectory = 16,
    //
    // Summary:
    //     The Fonts folder.
    Fonts = 20,
    //
    // Summary:
    //     The directory that serves as a common repository for application-specific
    //     data for the current user.
    ApplicationData = 26,
    //
    // Summary:
    //     The Windows folder.
    Windows = 36,
    //
    // Summary:
    //     The program files directory.
    ProgramFiles = 38,
    //
    // Summary:
    //     The "My Pictures" folder.
    //     Supported only on Windows Mobile.
    MyPictures = 39,
}

Tuesday, May 22, 2007 10:01:08 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  | 

 

SDF Sample: Showing the Entire String Contents of a ComboBox DropdownList#

Following Chris' SDF Samples (here, here and here) here is another little tip that reminded me we had this functionality in the Smart Device Framework while talking to a customer facing this issue.

Problem
I have a combobox with the following items in the list:

  1. Red
  2. Green
  3. A very dark and drab Gray

When you run your application you get something like this:

Your users call your helpdesk (and if you are like us the developers are the help desk :)) and complain they can't see the last colour option.

Solution
[Tested using Windows Mobile 5 emulator and Smart Device Framework 2.1]

Two possible solutions to this.  First, manually extend the ComboBox via the Visual Studio designer.  This is fine, but what happens if you create forms dynamically (as many of our customer do).

Second solution is found in OpenNETCF.Windows.Forms.ComboBox2 class and the DropDownWidth property.  Setting this property you get this:

Now if you have a dynamic form you can use this helper method to dynamically size the DropDownWidth.

private void AutoSizeDropDownWidth(OpenNETCF.Windows.Forms.ComboBox2 comboBox)
{
    int margin = 10;
    using (Graphics g = this.CreateGraphics())
    {
        SizeF size = SizeF.Empty ;
        int largestWidth = comboBox.Width + margin;
        for (int x = 0; x < comboBox.Items.Count; x++)
        {
            size = g.MeasureString(this.comboBox21.Items[x].ToString(), this.comboBox21.Font);
            largestWidth = ((int)size.Width>largestWidth ? (int)size.Width + margin: largestWidth );
        }
        comboBox.DropDownWidth = largestWidth;
    }
}


Wednesday, April 25, 2007 4:04:26 PM (Eastern Daylight Time, UTC-04: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