By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,761 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,761 IT Pros & Developers. It's quick & easy.

Can't pass data to another form.

P: n/a
Hi All,

I can't pass data to another form:
in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.

Jul 11 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,

I can't pass data to another form:

in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.
I have resolved this issue.

I added the new form from the new button of toolbar.

It seems I have to add the new form from right mouse click of solution
explore.

Best regards,
Boki.

Jul 11 '07 #2

P: n/a
On Jul 11, 11:31 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.

I have resolved this issue.

I added the new form from the new button of toolbar.

It seems I have to add the new form from right mouse click of solution
explore.

Best regards,
Boki.
OK, sorry, it is not the root cause.

I got strange here, when I show form2 from form1, the string pass
well, but when I pass from form2, it never works.
/* this is form 1 code to show form 2*/
public void button1_Click(object sender, EventArgs e)
{
...

Form2 frm2 = new Form2();
frm2.textBox1.Text = "testing from form1"; /* this line
works well */
frm2.Show();
...

}

namespace Ring_Buffer_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.textBox1.Text = "dsfsdf"; /* this line makes nothing
happen */
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}
}
Best regards,
Boki.

Jul 11 '07 #3

P: n/a
On Jul 11, 11:42 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 11:31 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.
I have resolved this issue.
I added the new form from the new button of toolbar.
It seems I have to add the new form from right mouse click of solution
explore.
Best regards,
Boki.

OK, sorry, it is not the root cause.

I got strange here, when I show form2 from form1, the string pass
well, but when I pass from form2, it never works.

/* this is form 1 code to show form 2*/
public void button1_Click(object sender, EventArgs e)
{
..

Form2 frm2 = new Form2();
frm2.textBox1.Text = "testing from form1"; /* this line
works well */
frm2.Show();
...

}

namespace Ring_Buffer_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.textBox1.Text = "dsfsdf"; /* this line makes nothing
happen */
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}

}

Best regards,
Boki.
OK, new test result.

the code really create a new form, not the original form I was
using...

How to let it only do reference things....
Best regards,
Boki.

Jul 11 '07 #4

P: n/a
On Jul 11, 11:49 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 11:42 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 11:31 am, Boki <bokit...@ms21.hinet.netwrote:
On Jul 11, 10:24 am, Boki <bokit...@ms21.hinet.netwrote:
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.
I have resolved this issue.
I added the new form from the new button of toolbar.
It seems I have to add the new form from right mouse click of solution
explore.
Best regards,
Boki.
OK, sorry, it is not the root cause.
I got strange here, when I show form2 from form1, the string pass
well, but when I pass from form2, it never works.
/* this is form 1 code to show form 2*/
public void button1_Click(object sender, EventArgs e)
{
..
Form2 frm2 = new Form2();
frm2.textBox1.Text = "testing from form1"; /* this line
works well */
frm2.Show();
...
}
namespace Ring_Buffer_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.textBox1.Text = "dsfsdf"; /* this line makes nothing
happen */
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Best regards,
Boki.

OK, new test result.

the code really create a new form, not the original form I was
using...

How to let it only do reference things....

Best regards,
Boki.
Hi

I try this way in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1.update_msg_string(textBox1.Text.ToString());
}
and put this in form1:

public void update_msg_string(string msg_str)
{
textBox1.Text = msg_str;
}
No luck yet, ....

Boki.

Jul 11 '07 #5

P: n/a
When you have one form create another that requires data to be exchanged, it
is not advisable to directly manipulate controls on the other form.

There are a number of ways to pass info between forms

eg in form1 you may have

Form2 form2 = new Form2 ();
form2.Tag = someObject;
form2.Show();
and in form2_Shown you can have
MyObject o = (MyObject) Tag;

You can also set properties in Form2 eg

public string SetMyText
{
get { myControl.Text = value; }
}
and in Form1 you would have
form2.SetMyText = "aaaa";

or you can use functions, event handlers etc
"Boki" <bo******@ms21.hinet.netwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi All,

I can't pass data to another form:
in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.
Jul 11 '07 #6

P: n/a
It's very early in the morning here

set { myControl.Text = value; } // not 'get'

"Ian Semmel" <an****@rocketcomp.com.auwrote in message
news:#N**************@TK2MSFTNGP04.phx.gbl...
When you have one form create another that requires data to be exchanged,
it is not advisable to directly manipulate controls on the other form.

There are a number of ways to pass info between forms

eg in form1 you may have

Form2 form2 = new Form2 ();
form2.Tag = someObject;
form2.Show();
and in form2_Shown you can have
MyObject o = (MyObject) Tag;

You can also set properties in Form2 eg

public string SetMyText
{
get { myControl.Text = value; }
}
and in Form1 you would have
form2.SetMyText = "aaaa";

or you can use functions, event handlers etc
"Boki" <bo******@ms21.hinet.netwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
>Hi All,

I can't pass data to another form:
in form2:

private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}

the form2 will close after button click, but the textbox1 of form1
doesn't change anything.

textbox1 of form1 already set to public.

Please advice.

Best regards,
Boki.
Jul 11 '07 #7

P: n/a
On Jul 12, 3:29 am, "Ian Semmel" <any...@rocketcomp.com.auwrote:
It's very early in the morning here

set { myControl.Text = value; } // not 'get'

"Ian Semmel" <any...@rocketcomp.com.auwrote in message

news:#N**************@TK2MSFTNGP04.phx.gbl...
When you have one form create another that requires data to be exchanged,
it is not advisable to directly manipulate controls on the other form.
There are a number of ways to pass info between forms
eg in form1 you may have
Form2 form2 = new Form2 ();
form2.Tag = someObject;
form2.Show();
and in form2_Shown you can have
MyObject o = (MyObject) Tag;
You can also set properties in Form2 eg
public string SetMyText
{
get { myControl.Text = value; }
}
and in Form1 you would have
form2.SetMyText = "aaaa";
or you can use functions, event handlers etc
"Boki" <bokit...@ms21.hinet.netwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi All,
I can't pass data to another form:
in form2:
private void button1_Click(object sender, EventArgs e)
{
Form1 form_copy = new Form1();
form_copy.textBox1.Text = "DSFDSFDS";
this.Close();
}
the form2 will close after button click, but the textbox1 of form1
doesn't change anything.
textbox1 of form1 already set to public.
Please advice.
Best regards,
Boki.
Why got up so early today ?

Jul 12 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.