设计模式中时控件不执行一些数据加载方法,或者与运行时外观有所不同
/// <summary>
/// 判断是否为设计模式
/// </summary>
/// <returns></returns>
protected bool IsDesignModel()
{
if (this.GetService(typeof(System.ComponentModel.Design.IDesignerHost)) != null || System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)
{
return true;
//界面设计模式
}
else
{
//运行时模式
return false;
}
}
public JHSDUCBase()
{
InitializeComponent();
if (IsDesignModel() == false)//运行时模式才执行以下代码
{
string tipLeft = GetSettingValueById("***", "");
bool btipleft = tipLeft == "1" ? true : false;
if (btipleft)
{
this.lbText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
}
}
}