A set of .NET Framework managed libraries for developing graphical user interfaces.
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.