为Windows mobile编写设计友好的控件[Writing designer friendly controls for Windows Mobile]
在 J2i.Net 上看到了这篇文章 Making Designer Friendly Controls 。 原文地址为Simon Hart 的 Writing designer friendly controls for Windows Mobile 。
原文主要说: 当你为Windows mobile 设计友好控件时需要确定你的代码是否运行在正确的设计时,也就是说是否运行在桌面系统上。那么,如果你的Mobile程序运行在桌面系统上时,你就不能调用设备上的dll了。
“One thing that you sometimes need when writing Visual Studio designer friendly controls for Windows Mobile, is knowing if your code is running in design time - which is essentially running on the desktop or not. You need to know this because if you are running on the desktop (design time) you don't want to call device specific dlls.”
下面的代码可以获得当前模式:
DesignMode
public static class DesignMode
{
private static byte _mode = 255;
public static bool IsTrue
{
get
{
if (_mode == 255)
_mode = AppDomain.CurrentDomain.FriendlyName.Contains("DefaultDomain") ? (byte)1 : (byte)0;
return _mode == 1;
}
}
}
{
private static byte _mode = 255;
public static bool IsTrue
{
get
{
if (_mode == 255)
_mode = AppDomain.CurrentDomain.FriendlyName.Contains("DefaultDomain") ? (byte)1 : (byte)0;
return _mode == 1;
}
}
}
可以这样调用
if (DesignMode.IsTrue)
{
//don't call coredll.dll
}
else
{
//call coredll.dll
}
{
//don't call coredll.dll
}
else
{
//call coredll.dll
}
posted on 2009-12-16 15:16 listenlisten 阅读(971) 评论(10) 编辑 收藏 举报