C# Put string into TextBox

后端 未结 3 1098
暖寄归人
暖寄归人 2020-12-02 00:34

I want to show the results of this code in my TextBox:

       string txtout1 = txtOrgText.Text.Replace(parm, txtTo.Text).ToString();
       txtout = txtout1;         


        
3条回答
  •  时光取名叫无心
    2020-12-02 01:01

    What you need to do is:

     txtout.Text = txtout1;
    

    This is because txtout1 is just a string of characters, while txtout is a full TextBox, with all the drawing and colouring and stuff like that.

    I see that you were on the right lines with your first line of code - txtOrgText.Text - the .Text is used both ways - for reading and writing. (Or "looking" and "changing" is another way of putting it.)

    You do this with a lot of other controls - a ComboBox, a Form (to set the caption), a DomainUpDown (the thing with the arrows on the right) to name a few.

    The reason that "ToString()" doesn't work is that ToString() is making your string of text into a string of text! It doesn't turn it into a TextBox for you.

提交回复
热议问题