Create platform dependent objects

L

Linus Rörstad

Hi!

I have a Windows Form with a Inputpanel on it which I'm using to get the
menubar with the SIP icon to appear. The problem is I also would like to run
the program on a ordinary PC(not the emulator). Can I make a object only if
the platform is pocket pc? Because right now the program throws an exception
while trying to open the form with the Inputpanel. The Microsoft.WindowsCE
namespace isn't available when running on the PC. Is there an attribute to
solve this?

Thanks
Linus Rorstad
PSI Systems
 
A

Alex Feinman [MVP]

No attribute, but you can wrap it into something like this:

public class SipWrapper : System.ComponentModel.Component
{
private InputPanel sip;
public SipWrapper()
{
/// <summary>
/// Required for Windows.Forms Class Composition Designer support
/// </summary>
InitializeComponent();

if ( Utils.IsPocketPC() )
{
sip = new InputPanel();
sip.EnabledChanged += new EventHandler(sip_EnabledChanged);
}
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion

public event System.EventHandler EnabledChanged;

public bool Enabled
{
set
{
if ( sip != null )
sip.Enabled = value;
}
get
{
if ( sip != null )
return sip.Enabled;
else
return false;
}
}

public Rectangle VisibleDesktop
{
get
{
if ( sip != null )
return sip.VisibleDesktop;
else
{
return Utils.GetVisibleDesktop();
}
}
}

private void sip_EnabledChanged(object sender, EventArgs e)
{
if ( EnabledChanged != null )
EnabledChanged(sip, new EventArgs());
}
}

The very simplistic PPC detection (sufficient for the needs of this app can
be done like this):

class Utils
{
public bool IsPocketPC()
{
try
{
LoadSIP();
return true;
}
catch
{
return false;
}

}
private void LoadSIP()
{
InputPanel ip= new InputPanel();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top