SmartPartInfo描述和实例
界面显示时有各种属性,而对这些属性的控制在SCSF中都是通过SmartPartInfo来进行控制,这样可以通过视图与不同的SmartPartInfo来控制视图的不同表现效果。
1. 在上面的项目中增加一个视图infoView,同时需要该视图继承一个IsmartPartInfoProvider的类,该类实现一个GetSmartPartInfo的方法,用于给容器调用。
[SmartPart] public partial class infoView : UserControl, IinfoView, ISmartPartInfoProvider { 。。。 #region ISmartPartInfoProvider 成员 public ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType) { ISmartPartInfo spi = null; if (smartPartInfoType.IsAssignableFrom(typeof(WindowSmartPartInfo))) { WindowSmartPartInfo wspi = new WindowSmartPartInfo(); wspi.Modal = true; wspi.MaximizeBox = false;//去掉最大化 wspi.MinimizeBox = false;//去掉最小化 wspi.ControlBox = true;
wspi.Keys[WindowWorkspaceSetting.TitleLabel] = this.label1;
spi = wspi; } else { spi = Activator.CreateInstance(smartPartInfoType) as ISmartPartInfo; } spi.Description = "this is info description"; spi.Title = "this.is info title"; return spi; } #endregion } |
2. 在项目Infrastructure.Library的类WindowWorkspace中的OnApplySmartPartInfo方法增加部分对应的代码:
protected override void OnApplySmartPartInfo(Control smartPart, Microsoft.Practices.CompositeUI.WinForms.WindowSmartPartInfo smartPartInfo) { 。。。 #region add the label to show the smartpartinfo title if (spi.Keys.ContainsKey(WindowWorkspaceSetting.TitleLabel)) { Label lb = (Label)spi.Keys[WindowWorkspaceSetting.TitleLabel]; lb.Text = spi.Title; } #endregion
} } |
3. 运行后结果如下:
图2.7.1