Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: Using new windows form

  1. #1

    Using new windows form

    Hi,

    I want to add new windows form in the present windows application. Which should be used to get some details from user and then i want those information back into my main form.
    Please help me to do this. I tried but iam able to show those in Form1 but unable to store that in Form1..

    Please suggest me here.

    Thanks a lot,
    Mayuri

  2. #2
    Hey!
    The easiest way would be to simply pass in a reference to the parent form. For example, inside your main form you'll have some code like:

    NewForm foo = new NewForm();
    foo.Parent = this;

    In your new form, you would be able to reference your parent form by checking your custom Parent property and setting values on it.


    Great, now even Kirupa is { facebooking | twittering }

  3. #3

    Re:

    Ya fine,
    But how can i pass the values from Form2 to Form1...?

    Ex: I have Form1 -- with button to go to Form2 n button to Show the Form2 Values And
    Form2 -- with 2 textBoxs to get values from user n 1 button to save n button to Exit.

    When Form1 opens i need to move to Form2 first, then user will enters the values n i will save it n Exit the Form2.
    When i click on Button from Form1 to Show values of Form2 which is entered by user, it should show the values in MsgBox r any thing....

    It will be a great help if you please suggest me to do this......

    Thanks a lot,
    Anjali ..


    Quote Originally Posted by kirupa View Post
    Hey!
    The easiest way would be to simply pass in a reference to the parent form. For example, inside your main form you'll have some code like:

    NewForm foo = new NewForm();
    foo.Parent = this;

    In your new form, you would be able to reference your parent form by checking your custom Parent property and setting values on it.


  4. #4
    Form1 and Form2 shouldn't know anything about each other. Instead you should have a "model" - ie. a class that will contain all the information you want to save. That class should be passed between the forms as a data container.

    The first form can pass an instance of the class to the second form, and when the second form is finished the class will be populated and the first form can reference the information stored therein.

  5. #5

    Thanks

    Hmm...thanks for this idea...
    I will surely try like this.

    Thanks a lot,
    Anjali ..



    Quote Originally Posted by TheColonial View Post
    Form1 and Form2 shouldn't know anything about each other. Instead you should have a "model" - ie. a class that will contain all the information you want to save. That class should be passed between the forms as a data container.

    The first form can pass an instance of the class to the second form, and when the second form is finished the class will be populated and the first form can reference the information stored therein.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012