Send data from one Win form to another
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Send data from one Win form to another

  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Question Send data from one Win form to another

    Hi,

    I made a secondary form named Form2 for my application in which the user can specify a Picture, Color and Text.

    Now, on this Form2, after the user presses OK button, I want to send the the particulars to Form 1 and open it up.
    For eg: If the user sets the color=Red, Picture=Img.gif, Text=Hi on Form2,
    then the TextBox on Form1 should display Hi in red color and a picture in the PicBox in Form1.

    How is the data sent form one form to another?

  2. #2
    Join Date
    Sep 2003
    Location
    London
    Posts
    81

    Re: Send data from one Win form to another

    See the documentation for System.Windows.Forms.OpenFileDialog (http://msdn.microsoft.com/en-us/libr...iledialog.aspx). A file dialog is used in the way you describe. It is instantiated, displayed, the user performs some action and the result is retrieved from the dialog by the calling code using public properties of the dialog. Make picture, colour and text public properties on Form2. Set them appropriately in the OK handler and then read them from Form1.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    10,967

    Re: Send data from one Win form to another

    Do you want to do this the simplest way or would you like an approach that will carry forward to WPF?

  4. #4
    Join Date
    Oct 2010
    Posts
    10

    Re: Send data from one Win form to another

    Arjay, can you provide a working example, or a link to one?

    This is still something I haven't mastered.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    10,967

    Re: Send data from one Win form to another

    Quote Originally Posted by CodeGuru12 View Post
    Arjay, can you provide a working example, or a link to one?

    This is still something I haven't mastered.
    Which approach are you looking for?

  6. #6
    Join Date
    Oct 2010
    Posts
    10

    Re: Send data from one Win form to another

    I guess examples of proper ways to share data between forms in a winforms application.

    I've seen people provide solutions, but no real world examples.

  7. #7
    Join Date
    Oct 2010
    Posts
    10

    Re: Send data from one Win form to another

    Can't edit my post. .. but wanted to also say Thanks!

  8. #8
    Join Date
    Oct 2010
    Posts
    5

    Re: Send data from one Win form to another

    I think the OP wanted to know how to pass data from form to form, not a OpenFileDialog.

    Here is a link with 4 methods:

    http://www.codeproject.com/KB/cs/pas...een_forms.aspx

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center