Jim
I made a custom control and it is provided with a ParentControlDesigner. As I pointed out in my comment, this is not an ideal solution for what you are asking. But this should be a good starting point. Oh, any FYI, I have this with a custom border color. I was inspired by yet another SO post to pursue this ... It was harder than I expected. To configure the parameters correctly, when performing border size adjustment, a PerformLayout call is made. Overriding to DisplayRectangle and calling SetDisplayRectLocation in OnResize causes the child controls to move correctly. In addition, the child controls do not have the expected “0,0” if in the upper left corner ... if the border width is not set to 0 ... And OnPaint provides a custom border drawing.
Good luck to you! Creating custom controls that are parents is difficult, but not impossible.
[Designer(typeof(ParentControlDesigner))] public partial class CustomPanel : UserControl { Color _borderColor = Color.Blue; int _borderWidth = 5; public int BorderWidth { get { return _borderWidth; } set { _borderWidth = value; Invalidate(); PerformLayout(); } } public CustomPanel() { InitializeComponent(); } public override Rectangle DisplayRectangle { get { return new Rectangle(_borderWidth, _borderWidth, Bounds.Width - _borderWidth * 2, Bounds.Height - _borderWidth * 2); } } public Color BorderColor { get { return _borderColor; } set { _borderColor = value; Invalidate(); } } new public BorderStyle BorderStyle { get { return _borderWidth == 0 ? BorderStyle.None : BorderStyle.FixedSingle; } set { } } protected override void OnPaint(PaintEventArgs e) { base.OnPaintBackground(e); if (this.BorderStyle == BorderStyle.FixedSingle) { using (Pen p = new Pen(_borderColor, _borderWidth)) { Rectangle r = ClientRectangle;
source share