how to pass value from one form to another? - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: how to pass value from one form to another?

  1. #16
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,595

    Re: how to pass value from one form to another?

    You'd do that using the Thread Tools menu at the top of the thread display page.

    However, for reasons not only you are entirely responsible for yourself, in the meantime this thread has mutated into some rather fundamental discussion. I, myself, for instance, am planning to make a rather elaborate post for which I did quite some research today, but didn't find the time to actually write the post yet, so I postponed it. So, unlike what's usually recommended (and you're doing good to ask for that ), it may be a good idea to still leave this particular thread in the unresolved state for some more time. OTOH, someone may find an appropriate title for a new thread to move that fundamental discussion to and starts it.

    At any rate, as the one who started the thread, you're the only one who can mark the thread resolved (maybe moderators can do that too, but they usually have more important things to do), so eventually it's up to you to decide. If you decide to leave the thread unresolved for the ongoing discussion, you may want to have a look at the thread from time to time, to see whether the discussion is finished in your opinion and then mark it resolved in this case. Of course that's not an issue at all if you're still interested in the discussion progress and thus further follow the thread anyway.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  2. #17
    Join Date
    Jun 2011
    Posts
    25

    Re: how to pass value from one form to another?

    Quote Originally Posted by TheGreatCthulhu View Post
    I have to insist, because, in the long run, if a beginner develops a habit of exposing private members, it's a rather bad thing (experienced developers can break or bend the rules, but only because they understand them well enough to do so). Good design is important, and, besides, what I'm proposed up there isn't that complicated at all.
    Sorry everyone - I forgot that was in there have deleted attachment. By the time I realised my mistake and prepared a correction I didn't have internet
    Thanks for the example project, am I right in assuming this would be appropriate when there is a requirement to pass data both ways i.e., using Show() as opposed to ShowDialog() ? My amended (now rather late) solution uses the "normal" method viz.
    Code:
    System::Void Form1::button1_Click(System::Object^  sender, System::EventArgs^  e) 
    {
       Form2^ form2 = gcnew Form2();
       form2->text = textBox1->Text;   // send text to form2
       form2->ShowDialog();
       textBox1->Text = form2->text;   // retrieve and display edited text from form2
    }
    and in Form2.h
    Code:
       public: property String^ text
       {
          String^ get() 
          {
             return textBox1->Text;
          }
          void set(String^ txt)
          {
             textBox1->Text = txt;
          }
       }
    I know the e.g. posted referred to 2-way but in the terms of the op I thought this adequate for modal dialogs and is much simpler to understand. I think it is the method advised by M.S. Any comments appreciated.
    Last edited by RogerD; March 16th, 2013 at 10:06 AM.

  3. #18
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,595

    Re: how to pass value from one form to another?

    Quote Originally Posted by RogerD View Post
    oject, am I right in assuming this would be appropriate when there is a requirement to pass data both ways i.e., using Show() as opposed to ShowDialog() ?
    The main difference between Show() and ShowDialog() is that when using the latter, the calling form (Form1 in TheGreatCthulhu's demo project) does not react to user interaction until the form shown modally (Form2) gets closed. And using that in the demo project, as it is designed, wouldn't make much sense, because the text box for the user to enter text is on Form1 and needs to remain user-operable. "Does not react to user interaction" does not mean the form gets frozen, however: It will still react to other events, so, for example, it can update a clock it displays in a timer tick handler.

    Another important difference between Show() and ShowDialog() is that the latter returns a value indicating which button the user clicked to close the form. For logical reasons, Show() can't do that: It returns immediately after making the subject form visible, and at that point it simply can't know which button the user will click sometime in the future.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center