Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


accesing a forms property from a different namespace

Posted on 2004-11-02
Medium Priority
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?
Question by:dotnet22
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 12471620
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");

Hope this helps.

Expert Comment

ID: 12471850

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.

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.

Author Comment

ID: 12476987
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...

Accepted Solution

noulouk earned 2000 total points
ID: 12477062
in your app:
string message=MyClassLibrary.myfunction("Hello");

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

Expert Comment

ID: 12479734

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.

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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