Getting a string from another form

This is a discussion on Getting a string from another form within the C# Programming forums, part of the General Programming Boards category; Hi guys, I have a program that i'm writing that does the following: Code: private void buttonclick( blah blah blah) ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    26

    Getting a string from another form

    Hi guys,

    I have a program that i'm writing that does the following:
    Code:
    private void buttonclick( blah blah blah)
    {
          Form f=new myForm();
          f.Show();
    }
    now once this new form opens i want the user to input some data, not too hard so far. But my problem is how do i get that data back into the main form?
    would i use something like
    Code:
       return myData;
    i've tried that but it never seems to work
    any help is greatly appreciated.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is an event. Invocate an event and pass the new data as an argument.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    26
    how exactly would i do that?

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Check out MSDN.

    http://msdn.microsoft.com/library/de...cstartpage.asp

    Check out my website for more software development links.

    http://www.dslextreme.com/users/kuphryn/links.html

    Kuphryn

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Create a property for your input form with the datatype you want to get. Then read that property if the form was closed successfully.

    Code:
    private void buttonclick( blah blah blah)
    {
    	Form f = new myForm();
    
    	if( f.ShowDialog() == DialogResult.OK )
    	{
    		yourvalueinthisformwhereyouneedit = f.YourProperty;
    	}
    }
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 11:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21