0

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

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

提前致谢!

4

1 回答 1

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

于 2012-07-03T10:00:43.077 回答