-1

I have looked at other questions asking about similar problems, but to my understanding my namespace and form name are correct, but am still giving me the error code

Form1.Dispose(bool): no suitable method found to override

What else can give this problem besides differering names for namespace and form in form1.designer.cs and form1.cs?

public partial class Form1 : Form
{

    public Form1()
    { 
        InitializeComponent();
    }
}


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.button2 = new System.Windows.Forms.Button();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.textBox2 = new System.Windows.Forms.TextBox();
        this.textBox3 = new System.Windows.Forms.TextBox();
        this.textBox4 = new System.Windows.Forms.TextBox();
        this.textBox5 = new System.Windows.Forms.TextBox();
        this.SuspendLayout();
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(22, 106);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(56, 20);
        this.button2.TabIndex = 1;
        this.button2.Text = "button2";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(123, 31);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(131, 20);
        this.textBox1.TabIndex = 2;
        this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged_1);
        // 
        // textBox2
        // 
        this.textBox2.Location = new System.Drawing.Point(123, 67);
        this.textBox2.Name = "textBox2";
        this.textBox2.Size = new System.Drawing.Size(130, 20);
        this.textBox2.TabIndex = 3;
        // 
        // textBox3
        // 
        this.textBox3.Location = new System.Drawing.Point(123, 106);
        this.textBox3.Name = "textBox3";
        this.textBox3.Size = new System.Drawing.Size(129, 20);
        this.textBox3.TabIndex = 4;
        this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged_1);
        // 
        // textBox4
        // 
        this.textBox4.Location = new System.Drawing.Point(23, 176);
        this.textBox4.Multiline = true;
        this.textBox4.Name = "textBox4";
        this.textBox4.Size = new System.Drawing.Size(230, 71);
        this.textBox4.TabIndex = 5;
        this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged_1);
        // 
        // textBox5
        // 
        this.textBox5.Location = new System.Drawing.Point(146, 149);
        this.textBox5.Name = "textBox5";
        this.textBox5.Size = new System.Drawing.Size(105, 20);
        this.textBox5.TabIndex = 6;
        this.textBox5.TextChanged += new System.EventHandler(this.textBox5_TextChanged);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 270);
        this.Controls.Add(this.textBox5);
        this.Controls.Add(this.textBox4);
        this.Controls.Add(this.textBox3);
        this.Controls.Add(this.textBox2);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.button2);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    private System.Windows.Forms.TextBox textBox4;
    private System.Windows.Forms.TextBox textBox5;
}
sab669
  • 3,984
  • 8
  • 38
  • 75
konto123
  • 11
  • 5

1 Answers1

0

Your form1.cs file makes Form1 a nested class, to be accessed as WindowsFormsApplication3.Person.Form1. This is because you put the closing brace for Person after Form1's definition. Using any decent editor's code formatting option should make this apparent.

WindowsFormsApplication3.Person.Form1 does not match WindowsFormsApplication3.Form1, so the base class is never seen for the latter.

  • Thanks, this solved that problem. But moving the brackets means that the textboxes inside of method KollaKön() does not exist in that context, do i need to move these parts private void textBox3_TextChanged_1(object sender, EventArgs e) { } private void textBox5_TextChanged(object sender, EventArgs e) { } into the person class? – konto123 Dec 13 '16 at 14:30
  • @konto123 Generally, no, it should be the other way around. Your `Person` class seems like it should hold the person's data, and possibly do things with that person's data, but not do things with the form. If you agree with that, then all the logic that does interact with the form needs to be moved to your `Form1` class. If you don't agree with that, you need to pass an instance of `Form1` to your `Person` class, so that you can access `form1.textBox5` rather than an unqualified `textBox5`. This in turn may mean you need to increase the visibility of the text boxes to make them accessible. –  Dec 13 '16 at 14:35
  • I got this to work, only to get another problem. When i run the compiler this piece of code: public string kollaKön() { string siffraAsString = form.textBox3.Text.Substring(8, 1); it gives a ArgumentOutOfReachException : "Start Index cannot be larger then length of string. The thing i cant understand is that i enter a string of 10 numbers, and the code should be picking the 9th number. But this is not the case according to the compiler, any clues why? – konto123 Dec 13 '16 at 15:24
  • @konto123 My first guess is that you're creating new instances of `Form1` instead of passing in the existing instance, meaning `form` isn't the form that the user is entering text into. At any rate, a minimal step in debugging would be figuring out what the value of `form.textBox3.Text` is. –  Dec 13 '16 at 16:43