C # Put a string in a TextBox

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

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

I have a text box txtOrgtext, in which the user enters text. I want to add text to txtout now. I set txtout to ReadOnly and MultiLine.

When I try to run my program, I get the following error:

Error   1   Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'   C:\Users\xxx\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 45  25  WindowsFormsApplication1

I tried txtout1.ToString(), but nothing has changed.

I also tried txtout.Text = txtout1and got this error:

Cross-thread operation not valid: 
Control 'txtout' accessed from a thread other than the thread it was created on.

I got an error because I used Threading, without Threading it works fine.

+5
source share
3 answers

What you need to do:

 txtout.Text = txtout1;

, txtout1 - , txtout - TextBox ..

, - txtOrgText.Text - .Text - . ( "" "" - .)

- ComboBox, Form ( ), DomainUpDown ( ), .

, "ToString()" , , ToString() ! TextBox .

+12

txtOut.Text = txtout1;

+4

It txtout = txtout1;will not be used in the first place , since txtout is a text field, and txtout1 is a string. You have to use

txtout.Text = txtout1

those. the Text property in the text box says Gets or Sets the current text in System.Windows.Forms.TextBox and its type is a string, since your txtout1 is already a string that does not need to be converted again using .ToString ()

+2
source

All Articles