C# How to change the value of a textbox on a UserC

2019-09-15 00:09发布

问题:

How would I be able to change the value of a textbox which is inside another form's usercontrol from another Form.

Code on UserControl2 of Form1:

public string TextValue
        {
            get
            {
                return textBox2.Text;
            }
            set
            {
                textBox2.Text = value;
            }
        }

Code on Form2

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count <= 0)
            {
                return;
            }
            int intselectedindex = listView1.SelectedIndices[0];
            if (intselectedindex >= 0)
            {
                u1.TextValue = listView1.Items[intselectedindex].Text;
            }


        }