TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Phil Saville
NA
13
0
Pass data between forms
Mar 2 2010 8:44 AM
hi there, im having trouble trying to pass strings from my 2nd windows form to my 1st windows forms...
i have two simple forms, the first just has just a button on which opens the 2nd form so the 2 forms are open at the same time. On this 2nd form i then have a text box and another button, the user will enter some text into the textbox and then press the button. Once this button is pressed i would like the text to be passed to the first form. I have tried using the following code...
Form1:
public partial class Form1 : Form
{
string text;
public Form1(string receivedText)
{
text = receivedText;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
this.Hide();
f.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
if (text == "")
{
}
else
{
label1.Text = text;
}
}
}
Form2:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1(textBox1.Text);
this.Hide();
}
}
This does not seem to work though and i get the error..." 'Pass.Form1' does not contain a constructor that takes '0' arguments.
Please help!
Reply
Answers (
6
)
Passing strings between windows forms
How to draw grid on window form?