Jannick

Jannick

  • NA
  • 3
  • 0

c# programming structure question

Mar 26 2009 6:10 AM
Hi,
I use ms Visual studio.

Problem discription :
 
I have 1 nameSpace and 3 classes :  -Main form class
                                                       -UserControl class
                                                       -Driver class

The driver class is used to acces a serial port. with methods etc.. for example(Serialport_Init()..Serielport_Write()..etc)

The UserControl class is used for a usercontrol form. I use it for data input to write to the Serialport.
This wil be expanded with several UserControl classes for more types of aplications and data input.

the Main Form class is used to display the serveral UserControl forms..
I want also to be able to select in the main form whitch Serial port I want to use..


The problem is How do i do that ?

I can't make for each Form main and UserControl forms a Driver serialDriver = new Driver();
because it will make several instances of the driver class.
I just want 1 Driver serialDriver = new Driver(); whitch i can acces from all of the classes.

maybe A Class in a Class, and in de main class definying The driver ?
something like this:

NameSpace SpaceName
{

Class Form1
{  Driver serialDriver = new Driver();
      Class Usercontrol1
      {
       }
       Class Usercontrol2
      {
      }
}

Class driver
{
}

} // end namespace

 
Could that work ?


I'm reading some C# books about interfacing, but that does not solve my problem i think.

             

Answers (2)