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

x
?
Solved

accesing a forms property from a different namespace

Posted on 2004-11-02
5
Medium Priority
?
193 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
Comment
Question by:dotnet22
[X]
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
5 Comments
 
LVL 9

Expert Comment

by:noulouk
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");
Console.WriteLine(message);

Hope this helps.
0
 
LVL 3

Expert Comment

by:chintan_vaishya
ID: 12471850
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
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...
0
 
LVL 9

Accepted Solution

by:
noulouk earned 2000 total points
ID: 12477062
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
ID: 12479734
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

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