C# How to change the value of a textbox on a UserControl on another Form

倖福魔咒の 提交于 2019-12-25 09:27:52

问题


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;
            }


        }

来源:https://stackoverflow.com/questions/43025191/c-sharp-how-to-change-the-value-of-a-textbox-on-a-usercontrol-on-another-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!