Solved

First Visual Studio C sharp program - deleted form once and recreated new one with same name giving an error when rebuilding the application

Posted on 2008-06-20
7
382 Views
Last Modified: 2013-12-16
I'm a newbie regarding C# sharp (VS 2008 C# express) so please forgive me.  I was following some exercies in Chaper 2 of Beginning C# 3.0 An Introduction to Object Oriented Programming.  I was trying to create a frmMain without any background coding.  My first attempt the form came up with coding so I deleted it and tried to add another new form with the same frmMain.cs name.  Now that I'm finished with adding labels and text boxes - I go to rebuild application I get an error - Error      1      'MailingLabel.frmMain.Dispose(bool)': no suitable method found to override      C:\Users\Stephen LeCompte\Documents\Visual Studio 2008\Projects\MailingLabel\MailingLabel\frmMain.Designer.cs      14      33      MailingLabel

With the highlight on the following code at Dispose...

protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

Can someone please tell me what's going on so I can prevent this from happening or how I may rebuild this application to test?
0
Comment
Question by:stephenlecomptejr
  • 3
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:photowhiz
ID: 21836147
"override" means to replace your base class's method of the same name with the one you're defining. It only makes sense if your base class actually defines a method with that name.

What is your base class? The class containing your method will start with something like:

    class ANameYouTypedIn : TheBaseClass
    {

What is "TheBaseClass" in your class?
0
 
LVL 10

Expert Comment

by:Marcjev
ID: 21837083
You should post some code. But I have to agree with photowhiz. A form need to pe derived from a base form. Usually this is Form, but it can also be from a form that is a child of Form so to speek.
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}

and then you can have:
   protected override void Dispose(bool disposing)
        {
...
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 21837995
Here is the code source under frmMain.cs

using System;
using System.Windows.Forms;

public class frmMain : Form
{
    #region Windows code
    private void InitializeComponent()
    {
    }
    #endregion

    public frmMain()
{
    InitializeComponent();

}

    public static void Main()
    {
        frmMain main = new frmMain();
        Application.Run(main);

    }

    private void btnDisplayOutput_Click(object sender, EventArgs e)
    {
        String buffer;

        buffer = "Mailing Label:" + Environment.NewLine + Environment.NewLine;
        buffer = buffer + "   Name: " + txtName.Text + Environment.NewLine;
        buffer = buffer + "Address: " + txtAddress.Text + Environment.NewLine;
        buffer = buffer + "    City: " + txtCity.Text + "    State: " + txtState.Text + "    Zip: " + txtZip.Text;

        txtResult.Text = buffer;

    }
}


Here is the code under frmMain.resx

<?xml version="1.0" encoding="utf-8"?>
<root>
  <!--
    Microsoft ResX Schema
   
    Version 2.0
   
    The primary goals of this format is to allow a simple XML format
    that is mostly human readable. The generation and parsing of the
    various data types are done through the TypeConverter classes
    associated with the data types.
   
    Example:
   
    ... ado.net/XML headers & schema ...
    <resheader name="resmimetype">text/microsoft-resx</resheader>
    <resheader name="version">2.0</resheader>
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
        <value>[base64 mime encoded serialized .NET Framework object]</value>
    </data>
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
        <comment>This is a comment</comment>
    </data>
               
    There are any number of "resheader" rows that contain simple
    name/value pairs.
   
    Each data row contains a name, and value. The row also contains a
    type or mimetype. Type corresponds to a .NET class that support
    text/value conversion through the TypeConverter architecture.
    Classes that don't support this are serialized and stored with the
    mimetype set.
   
    The mimetype is used for serialized objects, and tells the
    ResXResourceReader how to depersist the object. This is currently not
    extensible. For a given mimetype the value must be set accordingly:
   
    Note - application/x-microsoft.net.object.binary.base64 is the format
    that the ResXResourceWriter will generate, however the reader can
    read any of the formats listed below.
   
    mimetype: application/x-microsoft.net.object.binary.base64
    value   : The object must be serialized with
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
            : and then encoded with base64 encoding.
   
    mimetype: application/x-microsoft.net.object.soap.base64
    value   : The object must be serialized with
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
            : and then encoded with base64 encoding.

    mimetype: application/x-microsoft.net.object.bytearray.base64
    value   : The object must be serialized into a byte array
            : using a System.ComponentModel.TypeConverter
            : and then encoded with base64 encoding.
    -->
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
      <xsd:complexType>
        <xsd:choice maxOccurs="unbounded">
          <xsd:element name="metadata">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
              </xsd:sequence>
              <xsd:attribute name="name" use="required" type="xsd:string" />
              <xsd:attribute name="type" type="xsd:string" />
              <xsd:attribute name="mimetype" type="xsd:string" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="assembly">
            <xsd:complexType>
              <xsd:attribute name="alias" type="xsd:string" />
              <xsd:attribute name="name" type="xsd:string" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="data">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
              <xsd:attribute ref="xml:space" />
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="resheader">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
              </xsd:sequence>
              <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:complexType>
          </xsd:element>
        </xsd:choice>
      </xsd:complexType>
    </xsd:element>
  </xsd:schema>
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
</root>

Here is the code under frmMain.Designer.cs

namespace MailingLabel
{
    partial class frmMain
    {
        /// <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.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txtName = new System.Windows.Forms.TextBox();
            this.txtAddress = new System.Windows.Forms.TextBox();
            this.txtCity = new System.Windows.Forms.TextBox();
            this.txtState = new System.Windows.Forms.TextBox();
            this.txtZip = new System.Windows.Forms.TextBox();
            this.btnDisplayOutput = new System.Windows.Forms.Button();
            this.btnExit = new System.Windows.Forms.Button();
            this.txtResult = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // label1
            //
            this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(75, 20);
            this.label1.TabIndex = 0;
            this.label1.Text = "Name:";
            //
            // label2
            //
            this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label2.Location = new System.Drawing.Point(12, 38);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(75, 20);
            this.label2.TabIndex = 1;
            this.label2.Text = "Address:";
            //
            // label3
            //
            this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label3.Location = new System.Drawing.Point(12, 68);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(75, 20);
            this.label3.TabIndex = 2;
            this.label3.Text = "City:";
            //
            // label4
            //
            this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label4.Location = new System.Drawing.Point(244, 68);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(40, 20);
            this.label4.TabIndex = 3;
            this.label4.Text = "State:";
            //
            // label5
            //
            this.label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label5.Location = new System.Drawing.Point(324, 68);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(29, 20);
            this.label5.TabIndex = 4;
            this.label5.Text = "Zip:";
            //
            // txtName
            //
            this.txtName.Location = new System.Drawing.Point(94, 9);
            this.txtName.Name = "txtName";
            this.txtName.Size = new System.Drawing.Size(321, 20);
            this.txtName.TabIndex = 5;
            //
            // txtAddress
            //
            this.txtAddress.Location = new System.Drawing.Point(94, 38);
            this.txtAddress.Name = "txtAddress";
            this.txtAddress.Size = new System.Drawing.Size(321, 20);
            this.txtAddress.TabIndex = 6;
            //
            // txtCity
            //
            this.txtCity.Location = new System.Drawing.Point(94, 66);
            this.txtCity.Name = "txtCity";
            this.txtCity.Size = new System.Drawing.Size(144, 20);
            this.txtCity.TabIndex = 7;
            //
            // txtState
            //
            this.txtState.Location = new System.Drawing.Point(284, 68);
            this.txtState.Name = "txtState";
            this.txtState.Size = new System.Drawing.Size(34, 20);
            this.txtState.TabIndex = 8;
            //
            // txtZip
            //
            this.txtZip.Location = new System.Drawing.Point(359, 68);
            this.txtZip.Name = "txtZip";
            this.txtZip.Size = new System.Drawing.Size(59, 20);
            this.txtZip.TabIndex = 9;
            //
            // btnDisplayOutput
            //
            this.btnDisplayOutput.Location = new System.Drawing.Point(12, 94);
            this.btnDisplayOutput.Name = "btnDisplayOutput";
            this.btnDisplayOutput.Size = new System.Drawing.Size(75, 23);
            this.btnDisplayOutput.TabIndex = 10;
            this.btnDisplayOutput.Text = "&Display";
            this.btnDisplayOutput.UseVisualStyleBackColor = true;
            this.btnDisplayOutput.Click += new System.EventHandler(this.btnDisplayOutput_Click);
            //
            // btnExit
            //
            this.btnExit.Location = new System.Drawing.Point(343, 94);
            this.btnExit.Name = "btnExit";
            this.btnExit.Size = new System.Drawing.Size(75, 23);
            this.btnExit.TabIndex = 11;
            this.btnExit.Text = "E&xit";
            this.btnExit.UseVisualStyleBackColor = true;
            //
            // txtResult
            //
            this.txtResult.Location = new System.Drawing.Point(13, 123);
            this.txtResult.Multiline = true;
            this.txtResult.Name = "txtResult";
            this.txtResult.Size = new System.Drawing.Size(405, 139);
            this.txtResult.TabIndex = 12;
            //
            // frmMain
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(427, 264);
            this.Controls.Add(this.txtResult);
            this.Controls.Add(this.btnExit);
            this.Controls.Add(this.btnDisplayOutput);
            this.Controls.Add(this.txtZip);
            this.Controls.Add(this.txtState);
            this.Controls.Add(this.txtCity);
            this.Controls.Add(this.txtAddress);
            this.Controls.Add(this.txtName);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Name = "frmMain";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Mailing Label Program";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.TextBox txtName;
        private System.Windows.Forms.TextBox txtAddress;
        private System.Windows.Forms.TextBox txtCity;
        private System.Windows.Forms.TextBox txtState;
        private System.Windows.Forms.TextBox txtZip;
        private System.Windows.Forms.Button btnDisplayOutput;
        private System.Windows.Forms.Button btnExit;
        private System.Windows.Forms.TextBox txtResult;
    }
}

Both frmMain.Designer.cs and frmMain.resx are under frmMain.cs

Can someone explain what the above means?  Thank you for your replies thus far.

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 7

Expert Comment

by:photowhiz
ID: 21839315
You do not need to post the .resx file.

One problem is that your frmMain.cs and frmMain.designer.cs classes are in different namespaces. That won't work, put:

    namespace MailingLabel
    {

after the using statements in your frmMain.cs file, and

    }

at the end.

Your designer class is partial but your form class is not. That is wrong, change your frmMain.cs class declaration to:

    public partial class frmMain : Form
0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 21850329
OK photowhiz....

I did as you stated under frmMain.cs - but I'm getting another error - Error      1      Type 'MailingLabel.frmMain' already defines a member called 'InitializeComponent' with the same parameter types      C:\Users\Stephen LeCompte\Documents\Visual Studio 2008\Projects\MailingLabel\MailingLabel\frmMain.Designer.cs      29      22      MailingLabel

Here is the code as it currently looks in frmMain.cs

using System;
using System.Windows.Forms;

namespace MailingLabel
{

    public partial class frmMain : Form
    {
        #region Windows code
        private void InitializeComponent()
        {
        }
        #endregion

        public frmMain()
        {
            InitializeComponent();

        }

        public static void Main()
        {
            frmMain main = new frmMain();
            Application.Run(main);

        }

        private void btnDisplayOutput_Click(object sender, EventArgs e)
        {
            String buffer;

            buffer = "Mailing Label:" + Environment.NewLine + Environment.NewLine;
            buffer = buffer + "   Name: " + txtName.Text + Environment.NewLine;
            buffer = buffer + "Address: " + txtAddress.Text + Environment.NewLine;
            buffer = buffer + "    City: " + txtCity.Text + "    State: " + txtState.Text + "    Zip: " + txtZip.Text;

            txtResult.Text = buffer;

        }
    }
}
Now when I double-click on the error I get directed to frmMain.Designer.cs with the highlight on Intialize Component...

namespace MailingLabel
{
    partial class frmMain
    {
        /// <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.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txtName = new System.Windows.Forms.TextBox();
            this.txtAddress = new System.Windows.Forms.TextBox();
            this.txtCity = new System.Windows.Forms.TextBox();


etc.  etc.  etc.
0
 
LVL 10

Accepted Solution

by:
Marcjev earned 500 total points
ID: 21850597
It seems you have 2 times a InitializeComponent method. It is both in frmmain.designer.cs and  in frmmain.cs. You can only have one!
In earlier times (before partial classes) this would be in frmmain.cs in a #region for generated code. From vc# 2005 onwards this in in the designer.cs code. So remove the code from FrmMain.cs
0
 
LVL 1

Author Closing Comment

by:stephenlecomptejr
ID: 31469320
I was not faithful in carrying out every step in the book and did not Add New Item - Code file and instead added a Form.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Runtime Exceptions when trying to submit data 28 51
ASP.NET MVC 2 31
Help with error when uploading excel file 3 26
start a process from a service 3 21
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now