2012-04-17 50 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 「通知設計師重繪的事件。