Changing a label's text in another form in C#?

后端 未结 12 1537
日久生厌
日久生厌 2020-11-30 09:12

I have a label called LabelX1. This is on form2. On form1, i have a button. I want the button\'s text to be transferred to the other form\'s label. I have tried

<         


        
12条回答
  •  孤独总比滥情好
    2020-11-30 09:31

    inside form2 write this

    public void ChangeLabel(string s)
    {
        labelX1.Text = s;
    }
    

    then where you create Form 2 do this

    form2 frm2 = new form2();
    frm2.ChangeLabel(this.button1.text);
    

提交回复
热议问题