dotnet / dotnet/winforms

No way to delete orphaned controls using the designer

Open
#12,827 1 comment 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
area-Analyzers/CodeFixes area-VSDesigner customer-reported
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### Environment

Visual Studio Professional 2022
Version 17.12.4

### .NET version

.NET 8

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

Unsure, we've only noticed recently.

### Issue description

We have a large Windows Forms project that we've migrated from .NET Framework 3.5 -> .NET Framework 4.8 -> .NET 8 during the last 5 years and we're finding forms that have a lot of orphaned controls. By that I mean controls that aren't attached to anything so you can't select them in the designer aside from the drop-down in the properties window.

We don't know how they got there, but we've not seen them prior to upgrading to .NET 8 which we used the .NET Upgrade Assistant for. They could have been there, but we haven't seen them until recently. They appear to have been generated a second time from existing controls that are in the form and then given the default name e.g. TabPage1 but that's just a guess. You can't actually select these inside the designer and its not possible to delete them without going into the designer generated code-behind file and deleting the code for them manually.

It would be nice if there was a compiler warning for orphaned controls and a way to delete them and their sub-controls from the designer itself so we don't have to risk breaking something.

### Steps to reproduce

Unfortunately, I don't know how they got there. They're not easy to identify unless you're looking for a control in the properties window drop-down and happen to stumble upon one that doesn't display a selection box around it or change the view (like switching a tab page for example - if you switch to one thats an orphaned control it doesn't have a tabcontrol attached to switch to).

### Diagnostics

```text
No output is written to the Windows Forms Output Window when selecting an orphaned control from the properties window drop-down.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.