Can I use both "Designer" and "DesignerAttribute" in a Winforms UserControl?

Jeffrey Gaines 80 Reputation points
2026-07-30T13:27:04.12+00:00

I am trying to create a Winforms UserControl that will act as a container for other controls AND use its own Designer.

I have used the following Microsoft examples:

ControlDesigner Class

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.design.controldesigner?view=windowsdesktop-10.0&viewFallbackFrom=net-5.0

Use Visual C# to make a UserControl object act as a control container design-time

https://learn.microsoft.com/en-gb/troubleshoot/developer/visualstudio/csharp/language-compilers/usercontrol-act-control-container-design-time

Both work exactly as expected.

The first has a white border when the mouse enters and no border when the mouse leaves.

The second accepts a controls such as a button or label which then move with the main control.

However, when I try to design a UserControl as follows:

namespace ControlDesignerExample

{

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]

[DesignerAttribute(typeof(ExampleControlDesigner))]

public partial class JContainerCtrl : UserControl

{

	public JContainerCtrl()

	{

		InitializeComponent();

	}

}

}

It will only do one or the other it will not do both.

Is it not possible to use both these attributes together or have I done something wrong?

An Internet search for "Winforms is it possible to use both Designer and DesignerAttribute in a UserControl" produces nothing useful.

Developer technologies | Windows Forms

Answer accepted by question author
Danny Nguyen (WICLOUD CORPORATION) 8,540 Reputation points Microsoft External Staff Moderator
2026-07-31T04:11:49.1366667+00:00

Hi @Jeffrey Gaines ,

The issue here is that Designer and DesignerAttribute are not two different mechanisms. DesignerAttribute is the attribute class, and [Designer(...)] is just the C# short attribute syntax for the exact same thing.

Applying both to the same UserControl will not combine two different designers into one design-time behavior. The framework expects the design-time behavior to be handled by a single associated designer class that implements IDesigner.

Since your control must support nested child controls at design time, the relevant base class to use is ParentControlDesigner, which provides the expected design-time dragging and dropping of nested controls. The documentation notes that for composite controls, you should derive your custom designer from ParentControlDesigner and then associate that designer with your control using a single DesignerAttribute.

Here is how you can implement this pattern so that it provides both the container abilities and your custom border logic:

using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace ControlDesignerExample
{
    // 1. Put a single [Designer(...)] attribute on the UserControl
    [Designer(typeof(ExampleContainerDesigner))]
    public partial class JContainerCtrl : UserControl
    {
        public JContainerCtrl()
        {
            InitializeComponent();
        }
    }

    // 2. Derive the custom designer from ParentControlDesigner instead of ControlDesigner
    public class ExampleContainerDesigner : ParentControlDesigner
    {
        private bool mouseover = false;

        protected override void OnMouseEnter()
        {
            mouseover = true;
            Control.Refresh();
        }

        protected override void OnMouseLeave()
        {
            mouseover = false;
            Control.Refresh();
        }

        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            if (mouseover)
            {
                pe.Graphics.DrawRectangle(Pens.White, 0, 0,
                    Control.Size.Width - 1,
                    Control.Size.Height - 1);
            }
        }
    }
}

This correctly preserves the container behavior from ParentControlDesigner while adding your custom visual border logic within the same designer.

If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.

Thank you. 

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

Answer accepted by question author

AI answer

2026-07-30T13:27:49.59+00:00

Designer and DesignerAttribute are not two different mechanisms here. DesignerAttribute is the attribute class, and [Designer(...)] is the short attribute syntax for the same thing.

Applying both to the same UserControl does not combine two designers into one design-time behavior. A DesignerAttribute specifies the class used to implement design-time services for a component. The designer class must implement IDesigner.

For a control that must support nested child controls at design time, the relevant designer base is ParentControlDesigner, which extends design-time behavior for controls that support nested controls. The documentation for composite controls says to derive the custom designer from ParentControlDesigner or DocumentDesigner, and then associate that designer with the control by using DesignerAttribute.

That means the correct approach is:

  1. Create a custom designer class.
  2. Derive that class from ParentControlDesigner instead of ControlDesigner.
  3. Put a single [Designer(...)] attribute on the UserControl that points to that custom designer.

Example pattern:

using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;

[Designer(typeof(ExampleContainerDesigner))]
public partial class JContainerCtrl : UserControl
{
    public JContainerCtrl()
    {
        InitializeComponent();
    }
}

public class ExampleContainerDesigner : ParentControlDesigner
{
    private bool mouseover = false;

    protected override void OnMouseEnter()
    {
        mouseover = true;
        Control.Refresh();
    }

    protected override void OnMouseLeave()
    {
        mouseover = false;
        Control.Refresh();
    }

    protected override void OnPaintAdornments(PaintEventArgs pe)
    {
        if (mouseover)
        {
            pe.Graphics.DrawRectangle(Pens.White, 0, 0,
                Control.Size.Width - 1,
                Control.Size.Height - 1);
        }
    }
}

This preserves the container behavior from ParentControlDesigner and adds the custom design-time behavior in the same designer.

So the issue is not that both attributes are syntactically invalid. The issue is that the design-time behavior needs to be implemented by one associated designer, and for a container control that designer should inherit from ParentControlDesigner.


AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.