Solved

Access object from more than one form

Posted on 2011-03-23
1
298 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# bracket error 3 35
Switching Visual Studio 2015 to normal debug display 3 37
C# winforms programmitically move panels 6 42
C# MVC Insert Multiple Row into DB 2 30
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…
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…
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…

791 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