dotnet22
asked on
accesing a forms property from a different namespace
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?
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(YourLocalPr operty);
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.
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(YourLocalPr
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.
ASKER
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...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.myf
Console.WriteLine(message)
Hope this helps.