开发者

How to use a ControlDesigner to Allow docking to Left and Right Only

Is there a way to create a controldesigner to allow for docking to left and right sides only? Instead of top, bottom, fill, etc... Thanks开发者_Go百科.


Changing the control designer requires a new control class so you can apply the [Designer] attribute. Once you go there, the cheap solution is to veto the selection in an override for the Dock property:

using System;
using System.Windows.Forms;

class MyControl : Control {
  public override DockStyle Dock {
    get { return base.Dock; }
    set { 
      if (value != DockStyle.None && value != (DockStyle.Left | DockStyle.Right))
        throw new ArgumentException("Ony None or Left+Right allowed");
      base.Dock = value;
    }
  }
}

If that's too crude, you can write a UITypeEditor so only the allowed dock styles can be selected and apply it to the overridden Dock property with the [Editor] attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜