Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Form1.cs--> fill up your details,has a submit button
Form2.cs-->has a web browser control,each time document completed event occurs fills a value from form1

What i have done is created an instance of Form2.cs when submit button in Form1.cs is pressed and navigated to a url. Now i want to fill the url input fiels with values from textboxes in Form1.cs ! Writing Form1.textBox1.Text didnt help!!
Updated 13-Feb-15 20:49pm
BillWoodruff 14-Feb-15 2:28am    
I have difficulty understanding what you describe. If you have a Form instance where you have entered information (Form1) which creates an instance of Form2: how can you say you have not "instantiated Form1" ?

Is there another Form in use here ? Please clarify which Form creates the other Forms, and when.
Rahul Anand Jha 14-Feb-15 2:50am    
I hope its clear now

This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:[^],[^].

Share this answer
The task of passing data from one Form to another is simple, and there are several well known ways to do it, including the use of Interface as preferred by Sergey, which is an excellent, and proven, technique,mastery of which will have many other benefits to you as a programmer.

OriginalGriff here on CodeProject has a series of three articles that demonstrate other ways to achieve this; this is Part 1, which has links to the other two articles: [^].

Your choice of technique might be based on the required sequence of transmission of data (workflow) ... item-at-a-time, or all-at-once ... or, the volume of information to be sent, the data Types involved. If you are transmitting a bunch of text-data, that's one thing; if you wish to pass instances of complex objects (Classes, Structs, etc.) that's another.

However, the task of getting the data you now have access to on Form2 into the URL fields in the currently opened web-page is the more difficult task here.

Is the web-page where you want to insert the data a web-page you have created and have control over ?
Share this answer
As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900