如何在打开文件时更改标签控制数据。 [英] How to change label control data while opening a file.

查看:79
本文介绍了如何在打开文件时更改标签控制数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我打开Excel文件这样的文件时,我想更新标签控制数据(文本)。



请回复。

Hi,

I want to update the label control data(text) when I open any file like Excel file.

Please reply.

推荐答案

它不起作用,因为你在UI(启动)线程上打开文件。你正在设置标签的文本,但由于线程正忙着打开并且可能处理文件,因此线程无法处理你的应用程序用新文本重新绘制标签的WM_PAINT消息。 />


在后台线程中放置和处理文件的代码,它会起作用。你可以使用显式线程,BackgroundWorker组件,任务并行库中的任务,或者你有什么。



哦!并且不要认为你可以只移动用于将标签文本设置为后台线程的代码。无论如何,它不可靠,不可靠。您无法从UI线程以外的任何其他方式触摸UI控件。
It doesn''t work because you''re opening the file on the UI (startup) thread. You''re setting the text of the label, but since the thread is busy opening and, possibly, processing the file, the thread cannot get around to processing the WM_PAINT messages your app got to repaint the label with the new text.

Put the code for opening and processing the file in a background thread and it''ll work. You can use explicit Threads, a BackgroundWorker component, Tasks from the Task Parallel library, or what have you.

Oh! And don''t think you can just move the code for setting the label text to the background thread. It won''t work, reliably anyway. You cannot touch UI controls from anything other than the UI thread.


这篇关于如何在打开文件时更改标签控制数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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