JavaScript EditorDhtml editor     Free javascript download 

Main Page

Because CWinFormsView::GetControl returns a pointer to System.Windows.Forms.Control, and not a pointer to WindowsControlLibrary1::UserControl1, it is advisable to add a member of the user control type and initialize it in IView::OnInitialUpdate. Now you can call methods and properties using m_ViewControl.

To create the MFC host application

  1. Open the MFC application you created in How to: Create the User Control and Host in a Dialog Box.

  2. Add the following line to the public overrides section of the CMFC02View class declaration in MFC02View.h.

    gcroot<WindowsControlLibrary1::UserControl1 ^> m_ViewControl;

  3. Add an override for OnInitialupdate.

    Display the Properties window (F4). In Class View (CTRL+SHIFT+C), select CMFC02View class. In the Properties window, select the icon for Overrides. Scoll down the list to OnInitialUpdate. Click on the drop down list and select <Add>. In MFC02View.cpp. make sure the body of the OnInitialUpdate function is as follows:

    В CopyCode imageCopy Code
    m_ViewControl = safe_cast<WindowsControlLibrary1::UserControl1 ^>(this->GetControl());
    m_ViewControl->textBox1->Text = gcnew System::String("hi");
  4. Build and run the project.

    On the Build menu, click Build Solution.

    On the Debug menu, click Start without debugging.

    Notice that the text box is now initialized.

See Also

JavaScript EditorDhtml editor     Free javascript download