【问题标题】:Resize border around control in custom DesignSurface在自定义 DesignSurface 中调整控件周围的边框
【发布时间】:2012-04-28 17:24:37
【问题描述】:

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

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

提前致谢!

【问题讨论】:

    标签: c# designer windows-forms-designer


    【解决方案1】:

    例如:改变控件的位置

    不喜欢这样:

    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”事件,通知设计者重绘。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 2015-03-04
      • 2011-01-12
      相关资源
      最近更新 更多