Sign in to follow this  
danromeo

[.net] C# MDX....Why can't I see the DX device?

Recommended Posts

danromeo    238
I have code resembling the following: -------FILE1.CS---------- namespace Engine{ public class MainForm : System.Windows.Forms.Form{ public Device device; } } --------FILE2.CS-------- namespace Engine{ public class View{ View(){ ..... WHY CAN'T I ACCESS THE DEVICE FROM HERE? } } } How can I access Device declared in the Mainform class from the constructor of the View class? The Visual Studio Intellisense sees the Engine namespace and the MainForm class, but it seems to only show the members of the native Form class.

Share this post


Link to post
Share on other sites
Scet    960
Well unless you make the device static, you're going to need an instance of the MainForm class. Unless there's something you're not showing us.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
A second way, and one that I use more commonly than making things static, is that I'd write the FILE2.CS as:

namespace Engine{
public class View{

Device TargetDevice;
View(Device targetDevice)
{
TargetDevice=targetDevice;
}
}
}

Using this method, you will always have a pointer to the device, the only thing to pay attention to is that if you don't set the reference (TargetDevice) to null before discarding the object it is pointing to, you will keep both objects around, the View, and the TargetDevice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this