Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How to get the MainForm reference?

$
0
0

I'm looking for a similiar call in C# for the C++ MFC call AfxGetApp().

 

From my mainForm I create and call a new class.  In this new class it something fails I want to be able to get a reference to the application or main form or whatever it is called in the .net environment so all my error handling is done in one place.

 

I know I can pass in a reference to the main form, but isn't there a way to access it from one of the many "namespaces". 

 

I assumed this would work, but it is NULL

 

P2IDlog

myDlog = (P2IDlog)TestADI.P2IDlog.ActiveForm;

 

Where TestADI is the namespace for my application and P2IDlog is the class for my "mainform".

The main form was created in the Main method.... Application.Run(new P2IDlog())

 

Any help would get great.

Chris


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>