VS 2022 the Form Designer screws up the Designer.cs file every time I change anything in the Form Design

Brad Howard 0 Reputation points
2023-07-15T22:19:02.7166667+00:00

Any Time I make a change to the Form using the IDE GUI designer, it causes many error to appear related to various Text Boxes, or any objects created on the Form. This is repeated Each time I make the smallest change on the Forms Design. Adding, editing, Moving even a tiny item.

Sample:

 public static DataGridView StatsGridView;
        public static System.Windows.Forms.Timer timer1;
        public static Label labelSmeterSValues;
        public static Label label10;
        public static GroupBox groupBox8;
        public static RadioButton radioButtonUSB;
        public static RadioButton radioButtonLSB;
        public static RadioButton radioButtonCWU;
        public static RadioButton radioButtonCWL;
        private static RadioButton radioButtonPSK;
        private static RadioButton radioButtonDATAU;
        private static RadioButton radioButtonDATAL;
        private static RadioButton radioButtonRTTYU;
        private static RadioButton radioButtonRTTYL;
        private static RadioButton radioButtonFM;
        private static RadioButton radioButtonAM;
        private static TextBox textBoxVFOAFreq;


All the "static" designations will be removed and the item will be rendered as an Error.

As long as I make No changes via the IDE GUI form Design All works fine. But even the Smallest change will blow up the Designer.cs file.

THIS SHOULD Never happen!!! These has to be a bug someplace in the IDE Form GUI designer.

This is causing Me A lot of time to correct it Each I must make a change to the Form.

Developer technologies | Windows Forms
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-07-17T07:31:01.1533333+00:00

    Hi @Brad Howard , Welcome to Microsoft Q&A.

    As Viorel said, the code for what you are doing is generated by winform itself , which is why it changes each time you modify it.

    Not in designer.csz you have some alternative options:

    One is to not use native controls, use custom controls.

    The second is to use code to customize and add controls, but you may need to have a concept of location and so on.

    You need to refer to the self-generated code to write or paste your own code into cs.

    Here is a simple code to add a button:

    using System;
    using System.Windows.Forms;
    namespace_7_17_2
    {
        public partial class Form1: Form
        {
            public Form1()
            {
                InitializeComponent();
                CreateCustomControls(); // Manually create controls after InitializeComponent
            }
            private static Button myButton = new Button();
            private void CreateCustomControls()
            {
                // Create the controls you need
                myButton.Text = "Custom Button";
                // Add the control to the placeholder control (such as a Panel control)
                this.Controls.Add(myButton);
                // Set properties such as control position and size
                // myButton. Location = ...
                // myButton. Size = ...
                //...
                // Add control event handling logic
                myButton.Click += MyButton_Click;
            }
            private void MyButton_Click(object sender, EventArgs e)
            {
                // Logic for handling button click events
            }
        }
    }
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

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