I have a .NET C# Windows Form app erroring on Form1.Designer.cs

-4

I have a problem with a .NET C# Windows Form application in which I cannot get the form to show in debug mode or release mode. It used to, so something must have changed. I don't know what but when I want to test it and see the form appear like it used to it doesn't. It's a form with a 3 tabbed control on it each doing different things.

When I rebuild the debug version and hit play nothing happens, no form is shown. No errors are shown in the build window when I build it either. So I start the debug nothing happens so I wait, it takes ages, and then I hit the pause button and it pauses on a random line e.g

this.lblTesting.Size = new System.Drawing.Size(45, 13);

with this error.

$exception error CS0103: The name '$exception' does not exist in the current context.

If I hit Continue then still no form shows and when I hit pause it just stops on this line.

this.tabControl.ResumeLayout(false);

With the error {"Exception of type 'System.StackOverflowException' was thrown."}

So I don't know how to rebuild the Form1.Designer.cs page so that it's all correct.

These were the errors I was getting after the final error.

Hunter.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Hunter.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\Reid\Documents\Visual Studio 2017\Projects\Hunter\Hunter\bin\Debug\Hunter.exe'. Symbols loaded.
'Hunter.exe' (CLR v4.0.30319: Hunter.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Hunter.exe' (CLR v4.0.30319: Hunter.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Hunter.exe' (CLR v4.0.30319: Hunter.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Hunter.exe' (CLR v4.0.30319: Hunter.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Hunter.exe' (CLR v4.0.30319: Hunter.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Hunter.exe' (CLR v4.0.30319: Hunter.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Process is terminated due to StackOverflowException.
An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll

The program '[22072] Hunter.exe' has exited with code -2147023895 (0x800703e9).

So I read some articles from here and other places that said to go to the form, add in something new or change something and then save the form and rebuild it and then the designer class for the form with problems should be rebuilt however that didn't seem to fix my problem.

I try adding in a new label next to another one on the Form1.cs [Design], and changed the code in Form1.cs to output something in it rather than change the whole value of the original label as it was doing.

This let me build it with no errors occurring.

However on Debug Play it did the same thing as before.

I then accidentally added a new form. I didn't want this form so I tried in the solution to right click expecting a "delete" or "remove form" option but none appeared. I went into the File Browser and just deleted anything that started with Form2. Then I read that I should open up the Hunter.csproj in notepad and remove references to that form which I did.

Now when I try to go to Form1.cs [Design] I get the error page that says:

The designer could not be shown for this file because none of the classes within it can be designed. 

Instances of this error (1)  
 
1.   Hide Call Stack 
 
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)  

I have tried using the "Clean Solution" option, "Run code analysis on solution", and "Rebuild" but I cannot get that form to show up. So I have no scooby doo what to do.

The link on the page takes me to > https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/design-time-errors-in-the-windows-forms-designer?f1url=%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(WhyDTELPage);k(TargetFrameworkMoniker-.NETFramework,Version%253Dv4.8)%26rd%3Dtrue&view=netframeworkdesktop-4.8

which is no good as there is no "ignore and continue" button shown or any yellow bar to go to the error. However if I search for the error at the top there is a section that says

The designer could not be shown for this file because none of the classes within it can be designed.

This error occurs when Visual Studio cannot find a base class that satisfies designer requirements. Forms and controls must derive from a base class that supports designers. If you're deriving from an inherited form or control, make sure the project has been built.

I just don't know why there is not "Fix" button, that will re-apply all the properties you have set on the actual Form Design page to the Form Designer Class. Or if you just saved the form page it rebuilds the class. There must be away to rebuild the class behind the form correctly from the properties and toolbox objects you created the form with? That would be a very good idea for Microsoft to add in to the IDE :), it analyses the code, any bugs and error messages and does its best to fix the project automatically.

So I have no idea what to do. How can I rebuild the whole Form1.Designer.cs class that I don't remember touching in the first place. How to get my form back, how to rebuild it so the form designer class is correct and run debug to actually see a form.

This is the whole class of the Form1.Designer.cs class -as requested by a comment to show

namespace Hunter
{
    partial class Form1
    {
        /// <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.tabControl = new System.Windows.Forms.TabControl();
        this.tabPage1 = new System.Windows.Forms.TabPage();
        this.lblLocalHostNameValue = new System.Windows.Forms.Label();
        this.listBoxPing = new System.Windows.Forms.ListBox();
        this.lstLocalIP = new System.Windows.Forms.ListView();
        this.lblLocalHostName = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.lblUserIPDetails = new System.Windows.Forms.Label();
        this.lblOnlineStatus = new System.Windows.Forms.Label();
        this.label6 = new System.Windows.Forms.Label();
        this.tabPage2 = new System.Windows.Forms.TabPage();
        this.lblStatus = new System.Windows.Forms.Label();
        this.lblCountry = new System.Windows.Forms.Label();
        this.cmdCancel = new System.Windows.Forms.Button();
        this.label1 = new System.Windows.Forms.Label();
        this.cmdClear = new System.Windows.Forms.Button();
        this.lblPing = new System.Windows.Forms.Label();
        this.ProgressBar = new System.Windows.Forms.ProgressBar();
        this.lblHostName = new System.Windows.Forms.Label();
        this.lblTesting = new System.Windows.Forms.Label();
        this.lblValidIP = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.txtIPAddress = new System.Windows.Forms.TextBox();
        this.cmdStartScan = new System.Windows.Forms.Button();
        this.PortScanResults = new System.Windows.Forms.ListView();
        this.tabPage3 = new System.Windows.Forms.TabPage();
        this.lblProxyListStatus = new System.Windows.Forms.Label();
        this.ProxyProgressBar = new System.Windows.Forms.ProgressBar();
        this.button2 = new System.Windows.Forms.Button();
        this.button3 = new System.Windows.Forms.Button();
        this.label10 = new System.Windows.Forms.Label();
        this.lstProxies = new System.Windows.Forms.ListView();
        this.tabControl.SuspendLayout();
        this.tabPage1.SuspendLayout();
        this.tabPage2.SuspendLayout();
        this.tabPage3.SuspendLayout();
        this.SuspendLayout();
        // 
        // tabControl
        // 
        this.tabControl.Controls.Add(this.tabPage1);
        this.tabControl.Controls.Add(this.tabPage2);
        this.tabControl.Controls.Add(this.tabPage3);
        this.tabControl.Dock = System.Windows.Forms.DockStyle.Top;
        this.tabControl.HotTrack = true;
        this.tabControl.ItemSize = new System.Drawing.Size(500, 18);
        this.tabControl.Location = new System.Drawing.Point(0, 0);
        this.tabControl.Name = "tabControl";
        this.tabControl.SelectedIndex = 0;
        this.tabControl.Size = new System.Drawing.Size(791, 401);
        this.tabControl.TabIndex = 1;
        // 
        // tabPage1
        // 
        this.tabPage1.Controls.Add(this.lblLocalHostNameValue);
        this.tabPage1.Controls.Add(this.listBoxPing);
        this.tabPage1.Controls.Add(this.lstLocalIP);
        this.tabPage1.Controls.Add(this.lblLocalHostName);
        this.tabPage1.Controls.Add(this.label3);
        this.tabPage1.Controls.Add(this.lblUserIPDetails);
        this.tabPage1.Controls.Add(this.lblOnlineStatus);
        this.tabPage1.Controls.Add(this.label6);
        this.tabPage1.Location = new System.Drawing.Point(4, 22);
        this.tabPage1.Name = "tabPage1";
        this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
        this.tabPage1.Size = new System.Drawing.Size(783, 375);
        this.tabPage1.TabIndex = 3;
        this.tabPage1.Text = "Home";
        this.tabPage1.UseVisualStyleBackColor = true;
        this.tabPage1.Click += new System.EventHandler(this.tabPage1_Click);
        // 
        // lblLocalHostNameValue
        // 
        this.lblLocalHostNameValue.AutoSize = true;
        this.lblLocalHostNameValue.Location = new System.Drawing.Point(105, 37);
        this.lblLocalHostNameValue.Name = "lblLocalHostNameValue";
        this.lblLocalHostNameValue.Size = new System.Drawing.Size(22, 13);
        this.lblLocalHostNameValue.TabIndex = 31;
        this.lblLocalHostNameValue.Text = "NA";
        // 
        // listBoxPing
        // 
        this.listBoxPing.FormattingEnabled = true;
        this.listBoxPing.Location = new System.Drawing.Point(403, 17);
        this.listBoxPing.Name = "listBoxPing";
        this.listBoxPing.Size = new System.Drawing.Size(354, 82);
        this.listBoxPing.TabIndex = 30;
        this.listBoxPing.SelectedIndexChanged += new System.EventHandler(this.listBoxPing_SelectedIndexChanged);
        // 
        // lstLocalIP
        // 
        this.lstLocalIP.HideSelection = false;
        this.lstLocalIP.Location = new System.Drawing.Point(15, 125);
        this.lstLocalIP.Name = "lstLocalIP";
        this.lstLocalIP.Size = new System.Drawing.Size(760, 182);
        this.lstLocalIP.TabIndex = 12;
        this.lstLocalIP.UseCompatibleStateImageBehavior = false;
        this.lstLocalIP.View = System.Windows.Forms.View.Details;
        // 
        // lblLocalHostName
        // 
        this.lblLocalHostName.AutoSize = true;
        this.lblLocalHostName.Location = new System.Drawing.Point(29, 37);
        this.lblLocalHostName.Name = "lblLocalHostName";
        this.lblLocalHostName.Size = new System.Drawing.Size(60, 13);
        this.lblLocalHostName.TabIndex = 29;
        this.lblLocalHostName.Text = "Host Name";
        // 
        // label3
        // 
        this.label3.AutoSize = true;
        this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label3.Location = new System.Drawing.Point(29, 15);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(349, 13);
        this.label3.TabIndex = 27;
        this.label3.Text = "Details about the local computer the program is running from";
        // 
        // lblUserIPDetails
        // 
        this.lblUserIPDetails.AutoSize = true;
        this.lblUserIPDetails.Location = new System.Drawing.Point(29, 90);
        this.lblUserIPDetails.Name = "lblUserIPDetails";
        this.lblUserIPDetails.Size = new System.Drawing.Size(111, 13);
        this.lblUserIPDetails.TabIndex = 26;
        this.lblUserIPDetails.Text = "Local Machine IP Info";
        // 
        // lblOnlineStatus
        // 
        this.lblOnlineStatus.AutoSize = true;
        this.lblOnlineStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.lblOnlineStatus.ForeColor = System.Drawing.Color.DarkBlue;
        this.lblOnlineStatus.Location = new System.Drawing.Point(102, 65);
        this.lblOnlineStatus.Name = "lblOnlineStatus";
        this.lblOnlineStatus.Size = new System.Drawing.Size(44, 13);
        this.lblOnlineStatus.TabIndex = 25;
        this.lblOnlineStatus.Text = "Offline";
        // 
        // label6
        // 
        this.label6.AutoSize = true;
        this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label6.Location = new System.Drawing.Point(29, 65);
        this.label6.Name = "label6";
        this.label6.Size = new System.Drawing.Size(76, 13);
        this.label6.TabIndex = 24;
        this.label6.Text = "Online Status: ";
        // 
        // tabPage2
        // 
        this.tabPage2.Controls.Add(this.lblStatus);
        this.tabPage2.Controls.Add(this.lblCountry);
        this.tabPage2.Controls.Add(this.cmdCancel);
        this.tabPage2.Controls.Add(this.label1);
        this.tabPage2.Controls.Add(this.cmdClear);
        this.tabPage2.Controls.Add(this.lblPing);
        this.tabPage2.Controls.Add(this.ProgressBar);
        this.tabPage2.Controls.Add(this.lblHostName);
        this.tabPage2.Controls.Add(this.lblTesting);
        this.tabPage2.Controls.Add(this.lblValidIP);
        this.tabPage2.Controls.Add(this.label2);
        this.tabPage2.Controls.Add(this.txtIPAddress);
        this.tabPage2.Controls.Add(this.cmdStartScan);
        this.tabPage2.Controls.Add(this.PortScanResults);
        this.tabPage2.Location = new System.Drawing.Point(4, 22);
        this.tabPage2.Name = "tabPage2";
        this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
        this.tabPage2.Size = new System.Drawing.Size(783, 375);
        this.tabPage2.TabIndex = 1;
        this.tabPage2.Text = "Port Scan";
        this.tabPage2.UseVisualStyleBackColor = true;
        // 
        // lblStatus
        // 
        this.lblStatus.AutoSize = true;
        this.lblStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.lblStatus.Location = new System.Drawing.Point(510, 17);
        this.lblStatus.Name = "lblStatus";
        this.lblStatus.Size = new System.Drawing.Size(61, 13);
        this.lblStatus.TabIndex = 26;
        this.lblStatus.Text = "WAITING";
        // 
        // lblCountry
        // 
        this.lblCountry.AutoSize = true;
        this.lblCountry.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.lblCountry.Location = new System.Drawing.Point(507, 94);
        this.lblCountry.Name = "lblCountry";
        this.lblCountry.Size = new System.Drawing.Size(95, 17);
        this.lblCountry.TabIndex = 25;
        this.lblCountry.Text = "Country: NA";
        this.lblCountry.Visible = false;
        // 
        // cmdCancel
        // 
        this.cmdCancel.Enabled = false;
        this.cmdCancel.Location = new System.Drawing.Point(530, 319);
        this.cmdCancel.Name = "cmdCancel";
        this.cmdCancel.Size = new System.Drawing.Size(112, 23);
        this.cmdCancel.TabIndex = 24;
        this.cmdCancel.Text = "Cancel";
        this.cmdCancel.UseVisualStyleBackColor = true;
        this.cmdCancel.Click += new System.EventHandler(this.cmdCancel_Click);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label1.Location = new System.Drawing.Point(180, -40);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(69, 20);
        this.label1.TabIndex = 23;
        this.label1.Text = "Waiting";
        // 
        // cmdClear
        // 
        this.cmdClear.Location = new System.Drawing.Point(412, 319);
        this.cmdClear.Name = "cmdClear";
        this.cmdClear.Size = new System.Drawing.Size(112, 23);
        this.cmdClear.TabIndex = 22;
        this.cmdClear.Text = "Clear";
        this.cmdClear.UseVisualStyleBackColor = true;
        this.cmdClear.Click += new 
        System.EventHandler(this.cmdClear_Click);
        // lblHostName
        // 
        this.lblHostName.AutoSize = true;
        this.lblHostName.Location = new System.Drawing.Point(507, 39);
        this.lblHostName.Name = "lblHostName";
        this.lblHostName.Size = new System.Drawing.Size(66, 13);
        this.lblHostName.TabIndex = 19;
        this.lblHostName.Text = "Host Name: ";
        this.lblHostName.Visible = false;
        // 
        // lblTesting
        // 
        this.lblTesting.AutoSize = true;
        this.lblTesting.Location = new System.Drawing.Point(36, 168);
        this.lblTesting.Name = "lblTesting";
        this.lblTesting.Size = new System.Drawing.Size(45, 13);
        this.lblTesting.TabIndex = 18;
        this.lblTesting.Text = "Testing:";
        this.lblTesting.Visible = false;
        // 
        // lblValidIP
        // 
        this.lblValidIP.AutoSize = true;
        this.lblValidIP.ForeColor = System.Drawing.Color.Blue;
        this.lblValidIP.Location = new System.Drawing.Point(122, 243);
        this.lblValidIP.Name = "lblValidIP";
        this.lblValidIP.Size = new System.Drawing.Size(30, 13);
        this.lblValidIP.TabIndex = 17;
        this.lblValidIP.Text = "Valid";
        this.lblValidIP.Visible = false;
        // 
        // label2
        // 
        this.label2.AutoSize = true;
        this.label2.Location = new System.Drawing.Point(36, 243);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(58, 13);
        this.label2.TabIndex = 16;
        this.label2.Text = "IP Address";
        // 
        // txtIPAddress
        // 
        this.txtIPAddress.Location = new System.Drawing.Point(36, 256);
        this.txtIPAddress.Name = "txtIPAddress";
        this.txtIPAddress.Size = new System.Drawing.Size(192, 20);
        this.txtIPAddress.TabIndex = 15;
        this.txtIPAddress.TextChanged += new System.EventHandler(this.txtIPAddress_TextChanged);
        // 
        // cmdStartScan
        // 
        this.cmdStartScan.Location = new System.Drawing.Point(648, 319);
        this.cmdStartScan.Name = "cmdStartScan";
        this.cmdStartScan.Size = new System.Drawing.Size(112, 23);
        this.cmdStartScan.TabIndex = 14;
        this.cmdStartScan.Text = "Start Scan";
        this.cmdStartScan.UseVisualStyleBackColor = true;
        this.cmdStartScan.Click += new System.EventHandler(this.cmdStartScan_Click);
        // 
        // PortScanResults
        // 
        this.PortScanResults.HideSelection = false;
        this.PortScanResults.Location = new System.Drawing.Point(36, 14);
        this.PortScanResults.Name = "PortScanResults";
        this.PortScanResults.Size = new System.Drawing.Size(430, 138);
        this.PortScanResults.TabIndex = 13;
        this.PortScanResults.UseCompatibleStateImageBehavior = false;
        this.PortScanResults.View = System.Windows.Forms.View.Details;
        // 
        // tabPage3
        // 
        this.tabPage3.Controls.Add(this.lblProxyListStatus);
        this.tabPage3.Controls.Add(this.ProxyProgressBar);
        this.tabPage3.Controls.Add(this.button2);
        this.tabPage3.Controls.Add(this.button3);
        this.tabPage3.Controls.Add(this.label10);
        this.tabPage3.Controls.Add(this.lstProxies);
        this.tabPage3.Location = new System.Drawing.Point(4, 22);
        this.tabPage3.Name = "tabPage3";
        this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
        this.tabPage3.Size = new System.Drawing.Size(783, 375);
        this.tabPage3.TabIndex = 2;
        this.tabPage3.Text = "Proxies";
        this.tabPage3.UseVisualStyleBackColor = true;
        // 
        // lblProxyListStatus
        // 
        this.lblProxyListStatus.AutoSize = true;
        this.lblProxyListStatus.Location = new System.Drawing.Point(18, 287);
        this.lblProxyListStatus.Name = "lblProxyListStatus";
        this.lblProxyListStatus.Size = new System.Drawing.Size(81, 13);
        this.lblProxyListStatus.TabIndex = 19;
        this.lblProxyListStatus.Text = "Checking Proxy";
        // 
        // ProxyProgressBar
        // 
        this.ProxyProgressBar.Location = new System.Drawing.Point(15, 241);
        this.ProxyProgressBar.Name = "ProxyProgressBar";
        this.ProxyProgressBar.Size = new System.Drawing.Size(760, 23);
        this.ProxyProgressBar.TabIndex = 18;
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(512, 314);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(112, 23);
        this.button2.TabIndex = 17;
        this.button2.Text = "Find Proxies";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // button3
        // 
        this.button3.Location = new System.Drawing.Point(647, 314);
        this.button3.Name = "button3";
        this.button3.Size = new System.Drawing.Size(112, 23);
        this.button3.TabIndex = 16;
        this.button3.Text = "Check Proxies";
        this.button3.UseVisualStyleBackColor = true;
        this.button3.Click += new System.EventHandler(this.button3_Click);
        // 
        // label10
        // 
        this.label10.AutoSize = true;
        this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.label10.Location = new System.Drawing.Point(15, 17);
        this.label10.Name = "label10";
        this.label10.Size = new System.Drawing.Size(48, 13);
        this.label10.TabIndex = 13;
        this.label10.Text = "Proxies";
        // 
        // lstProxies
        // 
        this.lstProxies.HideSelection = false;
        this.lstProxies.Location = new System.Drawing.Point(15, 41);
        this.lstProxies.Name = "lstProxies";
        this.lstProxies.Size = new System.Drawing.Size(760, 182);
        this.lstProxies.TabIndex = 12;
        this.lstProxies.UseCompatibleStateImageBehavior = false;
        this.lstProxies.View = System.Windows.Forms.View.Details;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(791, 413);
        this.Controls.Add(this.tabControl);
        this.Name = "Form1";
        this.Text = "Proxy Hunter";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.tabControl.ResumeLayout(false);
        this.tabPage1.ResumeLayout(false);
        this.tabPage1.PerformLayout();
        this.tabPage2.ResumeLayout(false);
        this.tabPage2.PerformLayout();
        this.tabPage3.ResumeLayout(false);
        this.tabPage3.PerformLayout();
        this.ResumeLayout(false);

    }
    #endregion

    private System.Windows.Forms.TabControl tabControl;
    private System.Windows.Forms.TabPage tabPage2;
    private System.Windows.Forms.TabPage tabPage3;
    private System.Windows.Forms.ProgressBar ProxyProgressBar;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Label label10;
    private System.Windows.Forms.ListView lstProxies;
    private System.Windows.Forms.Label lblCountry;
    private System.Windows.Forms.Button cmdCancel;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Button cmdClear;
    private System.Windows.Forms.Label lblPing;
    private System.Windows.Forms.ProgressBar ProgressBar;
    private System.Windows.Forms.Label lblHostName;
    private System.Windows.Forms.Label lblTesting;
    private System.Windows.Forms.Label lblValidIP;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.TextBox txtIPAddress;
    private System.Windows.Forms.Button cmdStartScan;
    private System.Windows.Forms.ListView PortScanResults;
    private System.Windows.Forms.Label lblStatus;
    private System.Windows.Forms.TabPage tabPage1;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label lblUserIPDetails;
    private System.Windows.Forms.Label lblOnlineStatus;
    private System.Windows.Forms.Label label6;
    private System.Windows.Forms.Label lblLocalHostName;
    private System.Windows.Forms.Label lblProxyListStatus;
    private System.Windows.Forms.ListView lstLocalIP;
    private System.Windows.Forms.ListBox listBoxPing;
    private System.Windows.Forms.Label lblLocalHostNameValue;
}
}
c#
.net
visual-studio
winforms
compiler-errors
asked on Stack Overflow Mar 11, 2021 by MonkeyMagix • edited Apr 3, 2021 by halfer

2 Answers

0

Well I've fixed it, not sure when or why it went wrong. Wish I could add more code into these boxes though to show people.

In the form1.cs default constructor was

public Form1()
{            
    InitializeComponent();

    Form1 frm = new Form1();

    frm.Show();

    this.DoFormChecks(); // my code to start the form and all 3 tabs init, creating 1 instance of a class I use and define columns for listviews. This WAS WORKING....
 }

So I changed this to

public Form1()
{
     InitializeComponent();            
}

Put a button on the 1st tab that wasn't originally there or needed and put the code behind that button e.g

private void cmdTab1Run_Click(object sender, EventArgs e)
{

    Form1 frm = new Form1();           

    this.DoTab1Checks();        // instead of this.DoFormChecks() so it only does anything related to that tab    
}

So I set my class up for each tab now, rather than once for the whole form as I used to.

It complies as it always did but now shows automatically without the frm.Show(); command used anywhere which was in the constructor.

And on every tab the start button does the same thing, creates a new Form1(), then init my class, then runs the code needed JUST for that tab.

It was working until I fell asleep at the desk one night woke up and it wasn't. Had no clue to what went wrong or anyway to fix it.

I guess the code behind this.DoFormChecks(); was trying to set column widths and initialise objects that couldn't be used on the 2nd/3rd tab or something.

I really have no idea but I guess it was down to the 3 tabbed control I was using that stopped it.

So it wasn't a case of rebuilding the Form1.Designer.cs as I thought and no error messages helped me work it out but it was just trial and error guess work that made it work.

Now I have 3 classes initialised at the same time if you got to all 3 tabs and hit the button rather than just one that used to do it all.

answered on Stack Overflow Mar 14, 2021 by MonkeyMagix
0
  1. About the designer crashing
    Usually there is something working in your designer.cs code or something breaks it because of logic in your default (parameterless constructor).

  2. Now, about your case
    A) Of course it crashes, I'm surprize this ever worked.
    I guess you didn't paste your actual code.
    You can't use a method/constructor inside the method/constructor like that, that's infinite recursion :)
    B) Why would you ever want to do this?
    You already have a form that will be shown.
    C)Whatever logic you want to perform, move it to the Load event

    public Form1()
    {
        InitializeComponent();
        this.Load += Form1_Load;
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
        this.DoFormChecks();
    }
    

3.Don't create Forms on every button click, it doesn't make sense and it wont' really help.
Do you have any static/global data that is initialized/verified in you constructor?Try to avoid this.
In any case, check your business logic again, that's where the problem is.

answered on Stack Overflow Mar 14, 2021 by George Vovos • edited Mar 14, 2021 by George Vovos

User contributions licensed under CC BY-SA 3.0