Solved

Access object from more than one form

Posted on 2011-03-23
1
296 Views
Last Modified: 2012-06-21
I have an object that I need to access from two forms.

frmLogin
frmMain

On frmLogin I need to open the connection and validate the user.
On frmmain i will need to work with the methods and events of CmiServer


//frmLogin
frmMain.CmiServer.OpenConnection()


//frmMain
        public static CmiServer CmiServer
        {
            get
            {
                if (_cmiServer == null)
                {
                    _cmiServer = new CmiServer();
                }

                return _cmiServer;
            }
        }


Are there other/better ways to do this?
0
Comment
Question by:JRockFL
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35202221
You really only have two options:
(1) Static members.
(2) Instantiate the class in the first class and then pass a reference to it into the second class.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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