2012-04-17 122 views
0

当我将控件放在自定义DesignSurface上时,绘制了“调整边框”。这是VS Designer的标准边框 - 点缀着8个“锚点”来调整控件大小。不幸的是,当我以编程方式更改控件的大小或位置时,此边框不会应用此更改本身。我必须取消选中,然后通过鼠标选择此控件强制重画。在自定义DesignSurface中调整控件边界的大小

我的问题是:如何从代码访问此边框并以编程方式强制重绘?

在此先感谢!

回答

0

例如:改变控件的位置

不喜欢这样的:

Control control = new Control(); 
control.Location=new Point(10,10); 

试试这个:

Control control = new Control(); 
PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(control)["Location"]; 
if (propertyDescriptor != null) 
{ 
    Point point = (Point)propertyDescriptor.GetValue(control); 
    point.Offset(5, 5); 
    propertyDescriptor.SetValue(control, point); 
} 

的PropertyDescriptor的方法 “的SetValue” 能发射“ComponentChanged “通知设计师重绘的事件。