Home > Back-end >  Can't delete controls from secondary Form
Can't delete controls from secondary Form

Time:08-06

I'm having problems with adding new forms. When I add a new Form to my existing one (Like this) the second Form is an exact copy of the main one and its controls cant be deleted or edited. Main form Secondary Form

This is the Designer for the 2nd form:

namespace ImageEditingAppV1
{
    partial class Form2
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 450);
            this.Text = "Form2";
        }

        #endregion
    }
}

And this is the code it has (which is empty):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ImageEditingAppV1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
    }
}

Is there a way to delete those controls or even better a way add empty Forms to my existing one?

CodePudding user response:

It sounds like you added an inherited form, which is read only. Besides adding existing forms, there are three other options.

  • New->Form
  • New->New Item->Select - Form
  • New->New Item->Select - Inherited Form

It appears you chose the latter. You should be able to simply delete it and create a new Form.

CodePudding user response:

By experimenting around a bit I found out why adding additional Forms to you main (with the method i mentioned above) produces forms identical to the original with controls that can't be edited or deleted. The name of the original Form is the root of the problem. Originally when creating a new WinForm project the Form's default name is Form1. At some point I changed the name of the Form (for whatever reason) to simply "Form", removing the "1". Reverting back to it's default name, Form1, allows me now to add additional Forms to my project and all of them are blank and ready for use.

Just in case someone out there runs to a similar problem.

  • Related