Results 1 to 2 of 2

Thread: [C#] Send Data?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    207

    [C#] Send Data?

    OK, I have a setup page with a folder browser dialog and a textbox displays the location of the selected directory. After the user hits OK, how do I send the directory from the setup page to another form?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [C#] Send Data?

    What do you mean by "send the directory"? Do you mean pass the String containing the folder path from one form to another? This question has been asked and answered many times. Passing data from one form to another is the same passing data from any object to any other object. Forms are just objects after all.

    To pass data into an object you need to either set a property or call a method and pass a parameter. As i said, this goes for forms too, as they are just objects. You need to declare a property or method in your second form that will accept a String and then pass it on internally to wherever it needs to go. If this form is ALWAYS going to need this path then the logical thing to do is to make this property or method the constructor. A constructor is a method named after the type and is executed when you use the "new" key word, e.g.
    CSharp Code:
    1. public partial class Form2 : Form
    2. {
    3.     public Form2(string path)
    4.     {
    5.         InitializeComponent();
    6.  
    7.         // Use path here as required.
    8.     }
    9. }
    Now when you create the form you pass it the path from the TextBox:
    CSharp Code:
    1. Form2 f2 = new Form2(this.TextBox1.Text);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width