Hi ...

Working on a new C# .NET Application ...

I have written many applications using Visual C++ 6.0 MFC using CWinApp derived classes and CFormView. Typicalled I would load configuration and framework stuff (logging, metrics, alerts ...) in the CApp Class. Then when I needed to access one of these objects from another object I would use AfxGetApp() to get access to objects in the CApp Class.

Also ... with regards to the gui I would use a CFormView derived class and then I was always able to get a pointer to this class to access the controls on the CFormView derived class.

Sample Code. The code below will demonstate how to access between the foundation classes.

Code:
// Get a pointer to the view
CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd(); 
CFrameWnd* pChild = pMainFrame->GetActiveFrame();
CTestView* pView  = (CTestView*)pChild->GetActiveView();  

// Get a pointer to the app
CTestApp *pApp = (CTestApp *)AfxGetApp(); 

// Write to the application status, a listbox on the view
pView->WriteLog("Inside destrctor for CVideo"); 

// Create a pointer to the Metric object and set the logging 
// object inside.
m_pMetrics = new CMetrics(); 
m_pMetrics->SetLog(pApp->GetLog());

Using C# .NET
I have created a Windows Application with a Form. I have placed a ListBox on the Form and would like to create a method that I can call from other objects that will be used to write to the ListBox on the Form.

Also ... Where would be a good place to load configuration data (registry settings ext. ) and then access this data. Would you create a singleton object and then access this ?? What is the stadard / recommended approach with this ...

Thanks,
Chris


Sample Code
This code was my attempt to write a message to the ListBox contained in the Form Class from the Video Class. This doe not work ... but builds with no errors.

Code:
// This is the Form Class with the ListBox

namespace Test
{
        public class Form1 : System.Windows.Forms.Form
        {
                private System.Windows.Forms.ListBox ListBoxStatus;
        }
        
        public void WriteStatusMessage(String strMessage)
        {
            this.ListBoxStatus.Items.Add(strMessage);
        }
}


// The Video Class will try to write a status message 

namespace Test
{
	public class Video
	{
		public Video()
		{
			
                       // Write a message when the Video object 
                       // is created
                       String strMessage = "Inside the Video Constructor";
                       Form1 NewForm = new Form1();
                       NewForm.WriteStatusMessage(strMessage); 
		}

		public int nColor;
		public int nHue;
		public string strComment;
	}
}