| |

VerySource

 Forgot password?
 Register
Search
View: 858|Reply: 7

How to make Form1's TextBox1 get the value in Form2's TextBox1

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-15 22:00:01
| Show all posts |Read mode
public string Form1_load (string txt)
{
return this.textBox1.Text = txt;
Ranch
}


         Form1 form method
-------------------------------------------------- -----------------------

private void button1_Click (object sender, System.EventArgs e)
{
Form1 f1 = new Form1 ();
f1.Form1_load (this.textBox1.Text);
}

Why can't the form of Form1 get the value? ?
Reply

Use magic Report

0

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-20 11:00:02
| Show all posts
pass form2 to form1

form2
 private void button_Click (object sender, EventArgs e)
        {
            Form1 frm = new Form1 (false, currentID);
            frm.ShowDialog ();
         }

form1
        bool modType;
        int currentNo;

        public Form1 (bool mType, int cNo)
        {
            InitializeComponent ();
            modType = mType;
            currentNo = cNo;
        }

 private void Form1_Load (object sender, EventArgs e)
        {
          textbox1.text = modType.toString ();
         }
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-20 13:36:02
| Show all posts
I also tried this method. .
   Form2 can be used to pop up the Form1 form. . No response without Frm.Show ()
Reply

Use magic Report

0

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-20 17:00:02
| Show all posts
You use construction parameters to pass and get the value at load. You must show it, otherwise you use proxy and event to pass
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-4-27 17:00:02
| Show all posts
What about the agent?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-27 22:30:02
| Show all posts
You can call the TextBox in Form2 to public!!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-27 22:45:01
| Show all posts
Give the TextBox.Text in Form2 to a public variable or attribute and you can get it again!!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-27 23:00:01
| Show all posts
Search "Passing an Object between Two .NET Windows Forms" on the codeproject website
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list