Sign in to follow this  

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

This topic is 4035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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
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

This topic is 4035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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