在自定义设计图面中调整控件周围的边框大小



当我在自定义 DesignSurface 上放置控件时,会绘制一个"调整大小边框"。它是VS Designer中众所周知的标准边框 - 点缀着八个"锚点"以调整控件的大小。当我以编程方式更改控件的大小或位置时,不幸的是,此边框不会应用此更改本身。我必须取消选择,然后通过鼠标选择此控件才能强制重绘。

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

提前感谢!

例如:更改控件的位置

不喜欢这样:

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" 事件。

最新更新