Solved

accesing a forms property from a different namespace

Posted on 2004-11-02
151 Views
Last Modified: 2010-04-15
I have a windows application that falls under the namespace MyApplication for instance. I've created a class library, which falls under the namespace MyClassLibrary that needs to access a public property of a form in MyApplication when it is passed into a class in MyClassLibrary. But MyClassLibrary doesn't recognize MyApplication namespace because I can't import it's namespace because it is an application therefore it's output is an .exe file and not a .dll... How can I access the property in MyApplication from MyClassLibrary?
0
Question by:dotnet22
    5 Comments
     
    LVL 9

    Expert Comment

    by:noulouk
    A library is made to work alone.
    The best way to do what you want is to define a public property in your library, set or modify the property with your app and when the property changes, do the job with your library.
    You can do the same with a function if you need a result:
    in MyClassLibrary:
    public string myfunction(string test)
    {
    return test;
    }
    in your app:
    string message=MyClassLibrary.myfunction("Hello");
    Console.WriteLine(message);

    Hope this helps.
    0
     
    LVL 3

    Expert Comment

    by:chintan_vaishya
    HI,

    You can access the property of MyApplication from MyClassLibrary by either passing it to one of the methods in the myClassLibrary or u can make local variables in MyClassLibrary by passing the properties in MyApplication in to the MyClassLibrary Constructor.

    Like,
    In MyApplication,

    public string YourLocalProperty;
    MyClassLibrary newObject = new MyClassLibrary(YourLocalProperty);

    In MyClassLibrary,
    public MyClassLibrary(string propertyFromMyApp)
    {
    string myProperty = propertyFromMYApp;
    // now use it anywhere
    }

    Or you can also create objects which will contain the values and pass it to the myclasslibrary (but the myclasslibrary should also include that class)

    Hope this will be useful.
    Good Luck.
    Chintan.
    0
     

    Author Comment

    by:dotnet22
    One thing I forgot to mention is that not only do I need to access it, I need to change the value in the calling application...
    0
     
    LVL 9

    Accepted Solution

    by:
    in your app:
    string message=MyClassLibrary.myfunction("Hello");
    Console.WriteLine(message);

    The string is setting depending on what the function returns. This is a typical language object oriented.
    0
     
    LVL 13

    Expert Comment

    by:dungla
    dotnet22,

    I think access property of winform from class library project is not the proper way. Bring your property to another DLL, just like object-oriented.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

    875 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

    13 Experts available now in Live!

    Get 1:1 Help Now