winform中自定义设计器的问题

fhfhrfhf 2017-08-31 05:18:10
public class TableControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
private const string ColumnWidthName = "ColumnWidth";
private const string RowHeightName = "RowsHeight";

protected override void PostFilterProperties(System.Collections.IDictionary properties)
{
#region MyRegion
try
{
MyTableControl m = (MyTableControl)this.Control;

if (!m.IsCustomColumnsWidth)
{
if (properties.Contains(ColumnWidthName))
{

PropertyDescriptor data = (PropertyDescriptor)properties[ColumnWidthName];
SerializeNoBrowsablePropertyDescriptor newattr = new SerializeNoBrowsablePropertyDescriptor(data, BrowsableAttribute.No);
properties[ColumnWidthName] = newattr;
}
}
else
{

if (properties.Contains(ColumnWidthName))
{

PropertyDescriptor data = (PropertyDescriptor)properties[ColumnWidthName];
SerializeNoBrowsablePropertyDescriptor newattr = new SerializeNoBrowsablePropertyDescriptor(data, BrowsableAttribute.Yes);
properties[ColumnWidthName] = newattr;


}


}

base.PostFilterProperties(properties);


}
catch (Exception ex)
{
throw ex;
}
#endregion


}




}

上面这个是设计器的代码,想要实现的功能是当自定义控件(MyTableControl)的属性IsCustomColumnsWidth为false时,其对应的属性ColumnWidth在属性面板中不显示,当为true时则显示,现在的问题是当在属性面板中改变了IsCustomColumnsWidth的属性后,无法立即在属性面板中立即显示或者不显示ColumnWidth属性,也就是无法立即刷新属性面板的内容,需要点击一下别的控件,再选中MyTableControl控件之后才会显示或者不显示ColumnWidth属性,请教各位大神,这个需要怎么解决呢?谢谢。SerializeNoBrowsablePropertyDescriptor类是用来修改ColumnWidth属性的特性Browsable为false.
...全文
109 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fhfhrfhf 2017-09-04
  • 打赏
  • 举报
回复
给出答案,在base.PostFilterProperties(properties);这条语句后面加上一句 TypeDescriptor.Refresh(this.Component);这条语句的注释是:从缓存中清除指定组件的属性和事件。这样就会造成VS的属性面板重新加载当前设计的控件的属性。那么改动了的属性的就会在属性面板中实时改变了。

8,834

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧