不断更新文本框(C#GUI)

编程入门 行业动态 更新时间:2024-10-11 19:16:29
本文介绍了不断更新文本框(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)

本文发布于:2023-11-12 11:08:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不断更新   文本框   GUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!