Sharing Cursor.WaitCursor and InputPanel in VS2005

Thu, August 11, 2005, 04:33 PM under MobileAndEmbedded
Most PPC apps use the SIP (see point 1 here). Now that resx files are compatible, many developers will try to share code at the windows forms level.

So rather than try to conditionally compile in or out the InputPanel do the following: in your desktop project only, simply add a file that provides stubs for the InputPanel class:
namespace Microsoft.WindowsCE.Forms {
public class InputPanel {
public event EventHandler EnabledChanged;
private bool mDummy;
public bool Enabled {
get { return mDummy; }
set { mDummy = value;}
Next hurdle will be changing the cursor. On the full framework, every control has a Cursor property and that is what you assign; on the compact framework, there is a single cursor which you access globally through Cursor.Current

So, add a new code file to your project (and share it in both projects) that has the following:
namespace YourNamespace {
public static class TheCursor {
public static void CursorCurrent(Control c, Cursor defaultOrWait) {
if (c != null) {
c.Cursor = defaultOrWait;
Cursor.Current = defaultOrWait;
Now, through a global find and replace (which I usually advocate against), replace all occurrences of:
Cursor.Current = Cursors.Default and
Cursor.Current = Cursors.WaitCursor
TheCursor.CursorCurrent(this, Cursors.Default) and
TheCursor.CursorCurrent(this, Cursors.WaitCursor) respectively.

If you get any compile errors it means you were assigning Cursor.Current from a method of a class that is not a control:
a) Review that design decision
b) If you stick with it, change the this to null

Now in your desktop project, wherever you were going to code the following:
someControlOrFormEtc.Current = Cursors.Default and
someControlOrFormEtc.Current = Cursors.WaitCursor
instead code:
TheCursor.CursorCurrent(someControlOrFormEtc, Cursors.Default) and
TheCursor.CursorCurrent(someControlOrFormEtc, Cursors.WaitCursor) respectively.
Comments are closed.