Texbox.Text from form A to Form B

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am learning c# and I have a problem. I would like to enter a username in
form A textbox and have it apper in form B testbox.

I have something like this

frmlaptopChk laptop = new frmlaptopChk();
txtusername.Text = laptop.txtUsername.Text ();

and when i run it, I get inaccessible due to its protection level

*Not this is from form B testbox
 
freddy,

In order to do it the way that you want to, you have to set the
txtUsername field in the frmlaptopChk class to public or internal (assuming
these forms are hosted in the same assembly), so that you can access the
field.

However, I would have the frmlaptopChk class fire an event when the
textbox changes, and have the other form respond to that event. It's a much
better design, and doesn't tightly couple everything together.
 
Hi,


freddy said:
I am learning c# and I have a problem. I would like to enter a username in
form A textbox and have it apper in form B testbox.

I have something like this

frmlaptopChk laptop = new frmlaptopChk();
txtusername.Text = laptop.txtUsername.Text ();

and when i run it, I get inaccessible due to its protection level

*Not this is from form B testbox


You have to make the value of Text available to the calling method.

There are more than one way of doing it.

One question, is formA a dialog? (you show it using ShowDialog() )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top