C#把字符串转换成文本框 [英] C# Put string into TextBox

查看:134
本文介绍了C#把字符串转换成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示此code在我的文本框的结果:

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

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

我有一个文本框, txtOrgtext ,在其中用户输入文本。我想提出一些文本txtout现在。
我已设置为txtout只读和多行。

I have a textbox, txtOrgtext, into which the user inputs text. I want to put some text into txtout now. I have set txtout to ReadOnly and MultiLine.

当我尝试运行我的程序,我得到以下错误:

When I try running 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

我试过 txtout1.ToString(),但没有任何变化。

这是我试图 txtout.Text = txtout1 和得到这个错误

an i tried txtout.Text = txtout1 and get this error

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

**

我得到erroe因为我用线程,
  不必穿线做工精细:)

i get erroe because i used Threading , without Threading work fine :)

**

推荐答案

您需要做的是:

 txtout.Text = txtout1;

这是因为 txtout1 就是一个字符的字符串,而 txtout 是一个完整的文本框,所有的绘画和着色之类的东西。

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.

我看你是对的线,你的code的第一线 - txtOrgText.Text - 在。文本使用两种方式 - 阅读和写作。 (或寻找和改变是把它的另一方式。)

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.)

您有很多其他控件的做到这一点 - 一个组合框,表格(可设置字幕),一个DomainUpDown(与右边的箭头的东西),仅举几例。

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.

这的ToString()不能正常工作的原因是toString()方法是使你的文本字符串转换成文本串!它不会把它变成一个TextBox你。

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.

这篇关于C#把字符串转换成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆