Click here to Skip to main content
15,901,373 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Updating form controls outside of form file Pin
Lavake15-Mar-09 4:06
Lavake15-Mar-09 4:06 
GeneralRe: Updating form controls outside of form file Pin
N a v a n e e t h15-Mar-09 5:21
N a v a n e e t h15-Mar-09 5:21 
QuestionProblem to communicate between forms [modified] Pin
roshihans14-Mar-09 3:44
roshihans14-Mar-09 3:44 
AnswerRe: Problem to communicate between forms Pin
N a v a n e e t h14-Mar-09 6:00
N a v a n e e t h14-Mar-09 6:00 
GeneralRe: Problem to communicate between forms Pin
roshihans14-Mar-09 16:08
roshihans14-Mar-09 16:08 
GeneralRe: Problem to communicate between forms Pin
N a v a n e e t h14-Mar-09 16:21
N a v a n e e t h14-Mar-09 16:21 
GeneralRe: Problem to communicate between forms Pin
roshihans14-Mar-09 17:33
roshihans14-Mar-09 17:33 
GeneralRe: Problem to communicate between forms Pin
N a v a n e e t h15-Mar-09 5:14
N a v a n e e t h15-Mar-09 5:14 
roshihans wrote:
But Form1 already include Form2.h (in my case Form1 act as a "parent" form, and instantiate Form2). So I think I can't declare Form2 (Form1^ form1) and keep the form1 object, like you have mentioned above


Fair point! You will get circular dependency problems. To solve this, you need to have good understanding about C++ compiling and linking.

You have to use forward declaration and declare parent form in child form's header file. Assume your parent form is named as PForm and child form as CForm. Here is how your PForm's header file looks like
public ref class PForm : public System::Windows::Forms::Form{
public:
    void UpdateText(String^ str) // used to update the text box text. This will be called from CForm.
    {
	textBox1->Text = str;
    }

    // your rest of code
};
Here is your CForm's header
ref class PForm; // forward declaring PForm

public ref class CForm : public System::Windows::Forms::Form{
public:
    CForm(PForm^ pf) // injecting dependency through constructor
    {
	InitializeComponent();
	pForm = pf;
    }

private: 
    System::Void textBox1_TextChanged(System::Object^, System::EventArgs^);
    PForm^ pForm; // Parent form's object used to update the control
};
CForm.cpp contains
#include "CForm.h"
#include "PForm.h"

System::Void CForm::textBox1_TextChanged(System::Object ^sender, System::EventArgs ^e){
	if(pForm != nullptr)
		pForm->UpdateText(textBox1->Text);
}
You show the CForm from PForm like
CForm^ cForm = gcnew CForm(this);
cForm->Show();
This should work fine. But if you use delegates, you can avoid all these and implementation will be pretty straight forward. So please stick with delegates unless you have a good reason to go with the above method.

Hope it is clear now. Smile | :)


GeneralRe: Problem to communicate between forms Pin
roshihans15-Mar-09 18:12
roshihans15-Mar-09 18:12 
QuestionDelegates for instance methods between AppDomains... Pin
MrBhbk11-Mar-09 10:28
MrBhbk11-Mar-09 10:28 
QuestionSingle Textbox EventHandler for all Pin
Badboy22TR9-Mar-09 14:23
Badboy22TR9-Mar-09 14:23 
AnswerRe: Single Textbox EventHandler for all Pin
ky_rerun10-Mar-09 5:00
ky_rerun10-Mar-09 5:00 
AnswerRe: Single Textbox EventHandler for all Pin
Badboy22TR10-Mar-09 12:07
Badboy22TR10-Mar-09 12:07 
QuestionUpdating a label's text automatically? (New programmer) Pin
TabascoSauce9-Mar-09 12:50
TabascoSauce9-Mar-09 12:50 
GeneralRe: Updating a label's text automatically? (New programmer) Pin
Luc Pattyn9-Mar-09 13:09
sitebuilderLuc Pattyn9-Mar-09 13:09 
GeneralRe: Updating a label's text automatically? (New programmer) Pin
TabascoSauce9-Mar-09 14:10
TabascoSauce9-Mar-09 14:10 
QuestionInt64 minus.... Pin
Thilek8-Mar-09 6:46
Thilek8-Mar-09 6:46 
AnswerRe: Int64 minus.... Pin
Mark Salsbery8-Mar-09 9:19
Mark Salsbery8-Mar-09 9:19 
AnswerRe: Int64 minus.... Pin
Dave Doknjas8-Mar-09 13:56
Dave Doknjas8-Mar-09 13:56 
Question(C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
zkii4-Mar-09 3:08
zkii4-Mar-09 3:08 
AnswerRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
led mike4-Mar-09 4:41
led mike4-Mar-09 4:41 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
zkii4-Mar-09 16:54
zkii4-Mar-09 16:54 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
led mike5-Mar-09 4:28
led mike5-Mar-09 4:28 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
zkii5-Mar-09 16:02
zkii5-Mar-09 16:02 
GeneralRe: (C++/CLI) "FileNotFoundException" raised in "Activator::GetObject()" method of Remoting programming Pin
led mike6-Mar-09 4:47
led mike6-Mar-09 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.