Because returns a pointer to , and not a pointer to
WindowsControlLibrary1::UserControl1, it is advisable to add a member of the user control type and initialize it in . Now you can call methods and properties using
To create the MFC host application
Open the MFC application you created in How to: Create the User Control and Host in a Dialog Box.
Add the following line to the public overrides section of the
CMFC02Viewclass declaration in MFC02View.h.
gcroot<WindowsControlLibrary1::UserControl1 ^> m_ViewControl;
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:
В Copy Code
CWinFormsView::OnInitialUpdate(); m_ViewControl = safe_cast<WindowsControlLibrary1::UserControl1 ^>(this->GetControl()); m_ViewControl->textBox1->Text = gcnew System::String("hi");
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.