Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Mobile Development: Move your Form

, 9 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Some code to make your smartdevice forms being moveable.

Although I do not yet know a use case for this, here comes some code to make your smartdevice forms being moveable.

As default, Windows forms on mobile devices are created always as maximized forms. There may be situations, where you need a moveable form. The trick in compact framework is to use SetWindowLong with WS_CAPTION style and apply that to your form.

  

To enable you to experiment more with Window Styles there is another demo enabling to check all known window styles with a form. Be warned, setting WS_DISABLED or some other styles will make your form inaccessible.

  

The above changes or Window Styles are well known to every native C Windows programmer. Possibly you are now curious what else can be done with a good background knowledge of Windows API programming.

Another nice piece of code is how to get a list of an enum type. The below needs a list of options to build the checkboxes in the form:

//build a list of chk options for WSYTLES
void buildOptions()
{
    string[] stylesList = winapi.getStyles();

    int iCount=0;
    foreach (string s in stylesList)
    {
        CheckBox chkBox = new CheckBox();
        chkBox.Left = offsetX;
        chkBox.Top = iCount * offsetY;
        chkBox.Size = new Size(widthX, heightX);
        chkBox.Text = s;
        uint uStyle = (uint)Enum.Parse(typeof(winapi.WINSTYLES),s,false);
        if ((uiCurrentStyle & uStyle) == uStyle)
            chkBox.Checked = true;
        chkBox.CheckStateChanged += new EventHandler(chkBox_CheckStateChanged);
        tabPage1.Controls.Add(chkBox);
        iCount++;
    }
}

But an enum can not be enumerated ( great wording <img src= " src="http://www.hjgode.de/wp/wp-includes/images/smilies/icon_smile.gif" /> ). Although you could build the list by hand, I am a lazy programmer. I already have entered all the values as an enum. But there is a solution:

public static string[] getStyles()
{
    List<string> list = new List<string>();
    foreach (WINSTYLES ws in GetValues(new WINSTYLES()))
    {
        list.Add(ws.ToString());
    }
    return list.ToArray();
}

with the special GetValues() function for the enum (WINSTYLES):

...
[Flags]
public enum WINSTYLES:uint{
    WS_OVERLAPPED =     0x00000000,    //#define WS_OVERLAPPED WS_BORDER | WS_CAPTION
...
    WS_MAXIMIZE=        0x01000000,
    WS_CAPTION =        0x00C00000,    //#define WS_CAPTION  0x00C00000L     /* WS_BORDER | WS_DLGFRAME  */
 ...
    WS_MAXIMIZEBOX=     0x00010000,
    WS_POPUPWINDOW=     0x80880000,     // Creates a pop-up window with WS_BORDER,
     // WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW
     // styles must be combined to make the window menu visible.
}        
...
//great stuff by http://ideas.dalezak.ca/2008/11/enumgetvalues-in-compact-framework.html
public static IEnumerable<Enum> GetValues(Enum enumeration)
{
    List<Enum> enumerations = new List<Enum>();
    foreach (FieldInfo fieldInfo in enumeration.GetType().GetFields(
          BindingFlags.Static | BindingFlags.Public))
    {
        enumerations.Add((Enum)fieldInfo.GetValue(enumeration));
    }
    return enumerations;
}

Have fun.

Download: MoveableForms Source and Binary - VS2008, WM5 SDK, WM6.5.3 DTK (Hits: 7, size: 98.51 KB)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hjgode

Germany Germany
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 9 Nov 2012
Article Copyright 2012 by hjgode
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid