views:

45

answers:

1

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.

+1  A: 

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.

Hans Passant