locked
How can I receive a return form Form2 ? RRS feed

  • Question

  • C++/CLI code :

    #include "Form2.h".

    void button1_Click(System::Object^ sender, System::EventArgs^ e) 

        Form2 dlg; 
        dlg.ShowDialog(); 

    I build a project(vs2008 c++/CLI), in the Form1, I add a Button. Then I add a new form(Form2).

    I need to the Form2 return a string to Form1. How can I do?

    Wednesday, July 11, 2012 1:16 AM

Answers

  • If you need the text from textBox1 of Form2, then try this:

    textBox1->Text = dlg.textBox1->Text;

    Also when you edit the Form2, select textBox1 and change the Modifiers property to Public or other appropriate.

    If you need other string, then define your own member (public: String ^ myText) inside Form2 and use it to exchange data.

    • Proposed as answer by Elegentin Xie Wednesday, July 18, 2012 3:57 AM
    • Marked as answer by Elegentin Xie Wednesday, July 18, 2012 3:57 AM
    Friday, July 13, 2012 7:58 AM

All replies

  • Where is this string? Does it originate from a textbox on the Form2? Is it a label?

    Your post is insufficient.

    Wednesday, July 11, 2012 1:31 AM
  • C++/CLI code :

    #include "Form2.h".

    private: System::void button1_Click(System::Object^ sender, System::EventArgs^ e)  //Form1

        Form2 dlg; 

        dlg.ShowDialog(); 

       textBox1->Text =    ; // <-----I need the textBox can receive the string("AAAAAA") coming form Form2.

     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {  //Form2
         textBox1->Text ="AAAAAA"; 
        }

    I build a project(vs2008 c++/CLI).

    In the Form1, I add a Button and  a textBox.

    Then I add a new form(Form2), then add a Button and a textBox too.

    I need  the Form2 to return a string to Form1. How can I do?

    Wednesday, July 11, 2012 2:29 AM
  • you can look the following forum

    http://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/

    • Proposed as answer by i1friend Thursday, July 12, 2012 8:54 AM
    Wednesday, July 11, 2012 4:53 AM
  • The code on the forum is c#, not c++/CLI.

    Friday, July 13, 2012 7:41 AM
  • If you need the text from textBox1 of Form2, then try this:

    textBox1->Text = dlg.textBox1->Text;

    Also when you edit the Form2, select textBox1 and change the Modifiers property to Public or other appropriate.

    If you need other string, then define your own member (public: String ^ myText) inside Form2 and use it to exchange data.

    • Proposed as answer by Elegentin Xie Wednesday, July 18, 2012 3:57 AM
    • Marked as answer by Elegentin Xie Wednesday, July 18, 2012 3:57 AM
    Friday, July 13, 2012 7:58 AM
  • When I program with VB6.0, it is very easy to create a dialog box to receive the user's input, and return the dialog input to program.

    I use the "InputBox" control, and the codes are very simple.

    Now I  program using C++/CLI, just want to achieve the similar function. There isn't "InputBox" control in the tool box. I add a new form(From2), and hope the new form(Form2) can return a string back to From1, but I can't make it.

    Saturday, July 14, 2012 2:42 AM
  • Hello,

    Since you have ask a new question about this issue, I suggest you review the answer on new thread:

    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/9fe24683-cc91-4c03-b369-859a3ef34e12/#9fe24683-cc91-4c03-b369-859a3ef34e12

    And I will mark the answer, here, using global variable method.

    Thanks for your understanding.

    Regards,

    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 18, 2012 4:01 AM