在 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.”
下面的代碼可以獲得當前模式:
DesignModepublic 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;
}
}
}
可以這樣調用
if (DesignMode.IsTrue)
{
//don't call coredll.dll
}
else
{
//call coredll.dll
}