Home » Windows OS

Add a class to Windows Form Project

I have a few forms for a project, I added an  3 existing classes  from another file:

I right clicked my project name and selected add -> existing item. VS will only recognize one of the .cs files.

All the classes are shown in the solution explorer.

Here is some code:


public void Save(ref VehicleListing vehicleListing, ref AuctionListing auctionListing, ref Listing listing)
            vehicleListing.Year = Convert.ToInt16(cboYear);
            vehicleListing.Make = Convert.ToString(txtMake);
            vehicleListing.Model = Convert.ToString(txtModel);
            vehicleListing.Engine = Convert.ToString(cboEngineType);
            vehicleListing.CoachBuilder = Convert.ToString(txtCoachBuilder);
            vehicleListing.VIN = Convert.ToString(txtChassis);
            vehicleListing.BodyType = Convert.ToString(txtBodyType);
            vehicleListing.Modifiers = Convert.ToString(txtModifyers);
            AuctionListing.Lot = Convert.ToString(txtLot);
            Listing.CountryOrigin = Convert.ToString(cboOrigin);
            Listing.EngineNumber = Convert.ToString(txtEngine);

The first ref is accepted the other two are not.

the err says "are you missing a using directive or assembly reference."

Thanks in Advance AL


1 Answer Found


Answer 1

When you copy a class  from a different project  to a new project - you need to look at the namespace of the project copied and change it to your project name so that you can use it without referencing.

You can change the namespace of the copied class - in the cs file  near the namespace directive


namespace Project1
public class Class1



Ali Hamdar (alihamdar.com)


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure