Skip to content

WinForms Designer Regression: Cannot Select EnableDesignMode-Exposed Panel by Click in .NET 9 #13763

@Overdrive77

Description

@Overdrive77

Environment

Summary

In WinForms .NET 9: (Version 17.14.10)
When building a custom UserControl that exposes an internal panel with 'EnableDesignMode', it is not possible to select this internal panel by clicking in the designer. All drag-and-drop operations add controls to the root UserControl, not the design-surface-exposed panel, unless the Document Outline is used.

This worked as expected in .NET Framework 4.8.1, where clicking the internal panel selected it for control drops.
In .NET 9, this is broken and makes composite control design much harder.


Minimal Repro

Steps to Reproduce

  1. Add the following minimal UserControl and designer to a .NET WinForms project:

    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;
    
    [Designer(typeof(DemoPanelDesigner))]
    public class DemoPanel : UserControl
    {
        private readonly Panel _contentPanel = new Panel();
    
        public DemoPanel()
        {
            _contentPanel.Dock = DockStyle.Fill;
            this.Controls.Add(_contentPanel);
        }
    
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Panel ContentPanel => _contentPanel;
    }
    
    public class DemoPanelDesigner : ParentControlDesigner
    {
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
    
            if (component is DemoPanel panel)
                EnableDesignMode(panel.ContentPanel, nameof(DemoPanel.ContentPanel));
        }
    }
  2. Build the project, open a Form in the designer, and add 'DemoPanel' to it.

  3. Try to drag a Button (or any control) and drop it inside the 'DemoPanel' surface.

  4. Observe the generated code:

    // Result:
    demoPanel1.Controls.Add(this.button1); // added to UserControl.Controls, not ContentPanel.Controls
  5. Open Document Outline (View > Other Windows > Document Outline), select 'ContentPanel', and add a Button again.

  6. Observe that it is now correctly added to the internal panel.

Expected Behaviour

Clicking inside a design-surface-exposed internal panel should select it, and controls dragged in should be added to that panel, not the root UserControl.

Actual Behaviour

  • Clicking in the designer surface always selects the UserControl itself.
  • Controls are always added to the root Controls collection, even when clicking inside the exposed sub-panel.
  • Only by selecting the sub-panel in Document Outline can controls be added correctly.

Why this Matters

  • Breaks the designer experience for any composite/custom controls.
  • Causes confusion, misplaced controls, and wasted developer time.
  • No obvious fix/workaround except using Document Outline, which is not discoverable or intuitive for most developers.

Environment

  • .NET 9 (also occurs in .NET 6/7/8, .NET Framework 4.8.1)
  • Visual Studio 2022 v17.10.x

Workarounds Tried

  • Using Document Outline: works but is not intuitive.
  • Custom designers/overrides: no effect.
  • Runtime logic: not relevant for design-time code.

Suggested Solution

  • Support hit-testing/selecting 'EnableDesignMode' sub-controls by mouse click in the designer.
  • At least provide an option or shortcut to route drop/selection to the correct design surface.

Thank you for considering!

.NET version

.NET 9

Did this work in a previous version of Visual Studio and/or previous .NET release?

.NET Framework 4.8.1

Issue description

When building a custom UserControl that exposes an internal panel with EnableDesignMode, it is not possible to select this internal panel by clicking in the designer. All drag-and-drop operations add controls to the root UserControl, not the design-surface-exposed panel, unless the Document Outline is used.

Steps to reproduce

  1. Add the following minimal UserControl and designer to a .NET WinForms project:

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

[Designer(typeof(DemoPanelDesigner))]
public class DemoPanel : UserControl
{
    private readonly Panel _contentPanel = new Panel();

    public DemoPanel()
    {
        _contentPanel.Dock = DockStyle.Fill;
        this.Controls.Add(_contentPanel);
    }

    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public Panel ContentPanel => _contentPanel;
}

public class DemoPanelDesigner : ParentControlDesigner
{
    public override void Initialize(IComponent component)
    {
        base.Initialize(component);

        if (component is DemoPanel panel)
            EnableDesignMode(panel.ContentPanel, nameof(DemoPanel.ContentPanel));
    }
}

2. Build the project, open a Form in the designer, and add `DemoPanel` to it.
3. Try to drag a Button (or any control) and drop it inside the `DemoPanel` surface.
4. Observe the generated code:

### Diagnostics

```text

Metadata

Metadata

Labels

area-VSDesignerWindows Forms out-of-proc designer related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions