不断更新文本框(C#GUI) [英] Constently updating textbox (C# GUI)

查看:87
本文介绍了不断更新文本框(C#GUI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新一段代码来处理从编码器到文本框的数据,以便用户可以不断地知道位置。 我猜测使用线程是我最好的选择,但我过去从未尝试过线程。 在发布此帖子之前我确实尝试过
使用线程,但它一直告诉我无法从线程中访问文本框。 我确定我做错了什么。 任何帮助将不胜感激。

I need to update a piece of code to handle pumping the data from an encoder to a text box so they user can constantly know the position.  I'm guessing using threading is my best bet but I have never attempted threading in the past.  I did try to use threading before posting this but it kept telling me I couldn't access the textbox from the thread.  I'm sure I'm doing something incorrectly.  Any help would be appreciated.

谢谢,

乔治

推荐答案

为了从线程或后台工作者追加文本,当当前代码在表单内部时,试试这个:

   BeginInvoke(new Action(()=> textBox1.AppendText(" some text")));

   BeginInvoke( new Action( ( ) => textBox1.AppendText( "some text" ) ) );

您也可以使用调用代替 BeginInvoke

You can also use Invoke instead of BeginInvoke.


这篇关于不断更新文本框(C#GUI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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