Adding a Class Reference to a C# Windows Forms

Posted on 2006-03-31
Last Modified: 2010-04-16
I have created a class in a seperate file and I want to use that class in my WindowsForm file, how can I reference the class in my WindowsForm file.
Question by:tsmolskow
    LVL 18

    Expert Comment

    by:Ravi Singh
    Hi, assuming your using Visual Studio .NET and the class is compiled into a DLL then you have to reference the DLL file by going to Project --> Add Reference --> Browse. You then have to refer to the class in your code by specifying its full namespace, e.g.:

    ClassNameSpace.ClassName object = new ClassNameSpace.ClassName();

    or you could add a using directive at the top of the file to include the namespace, then you can simply refer to the class using its name.

    If its just a .cs file then you can add that file into your project by going into Project --> Add Existing Item and again, use the same method above to refer to it in your code.
    LVL 18

    Accepted Solution

    Sorry, don't call your object reference "object" like I did in my example, its a class in the framework!

    Author Comment

    It is a cs file, and I have added it to the project from the solution, but I'm not sure what to do next, can you give me some code example.
    LVL 7

    Expert Comment

    once you have declared the instance you can use the methods with dot notation so.....

    ClassName obj = new ClassName();

    obj.MethodName(Arg1, Arg2);

    for methods returning values....

    string str = obj.MethodName(Arg1, Arg2);

    hope this helps.


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 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

    23 Experts available now in Live!

    Get 1:1 Help Now