Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / March 2005

Tip: Looking for answers? Try searching our database.

need help passing data from form1 to form2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
E Stafford - 17 Mar 2005 19:49 GMT
Greetings,
I am having trouble trying to pass data from one form to another within
the same application.

My project is set up with a main form [Form1] and I added a second form
containing a richtextbox control using "add windows form" from the
solution explorer [Form2].
What I want to do is open Form2 from Form1 and then send data from a
richtext control named MessageErrors in Form1 to a RichText control
named errorText in Form 2.

From Form1 I used this code to open form2:

Form reports = new Form2();
reports.show();

The form opens up fine.

Now if I add the following code to Form2, I get the error: An Object
reference is required for the nonstatic field, method, or property
"app1.Form1.MessageErrors"

errorText.Text = Form1.MessageErrors.Text;

Fine, I need an object reference. So now I added:

Form1 form1 = new Form1();
errorText.Text = form1.MessageErrors.Text;

Now the application compiles without errors and I can call the function
to open Form2
But the errorText control in Form2 is blank and does not get the text
value from MessageErrors control in Form1.

I also tried using the following code in form1:

Form reports = new Form2();
reports.show();
reports.errorText.Text = messageErrors.Text;

but I get an error stating that:
'System.Windows.Forms.Form' does not contain a definition for errorText'

I am obvoiously missing something here.
I have searched the web and other forums for an answer without success.
Can anyone help me figure this out?
Tim Wilson - 17 Mar 2005 20:09 GMT
If you just need to pass the rich textbox text in to an instance of Form2,
and it doesn't need to be continuosly synced with the rich textbox on Form1,
then I would say create a constructor in Form2 that accepts a string
representing the text to place in the rich textbox. Something like this.

public Form2 (string displayData)
{
   InitializeComponent();
   this.richTextBox1.Text = displayData;
}

Then when you create an instance of Form2, use the constructor overload that
accepts a string.
Form2 f = new Form2(this.richTextBox1.Text);

Signature

Tim Wilson
.Net Compact Framework MVP

> Greetings,
> I am having trouble trying to pass data from one form to another within
[quoted text clipped - 42 lines]
> I have searched the web and other forums for an answer without success.
> Can anyone help me figure this out?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.