如何调用状态栏中的进度条? [英] How to Invoke the progress bar in Status strip?

查看:102
本文介绍了如何调用状态栏中的进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来调用应用程序中主UI线程上的控件.我的状态栏中的进度栏​​没有InvokeRequired,我需要以某种方式调用System.Windows.Forms.ToolStripProgressBar.

I am using the following code to invoke the controls that are on the main UI thread in my application. The progress bar that I have in my Status Strip does not have a InvokeRequired, I need to somehow invoke the System.Windows.Forms.ToolStripProgressBar.

if (txtbox1.InvokeRequired)
{
    txtbox1.Invoke(new MethodInvoker(delegate { txtbox1.Text = string.Empty; }));
}

推荐答案

自己找到了.

Found it myself.

System.Windows.Forms.ToolStripProgressBarprgBarMain.GetCurrentParent().InvokeRequired


Sevak是正确的!如果控件没有控件,则可以始终使用父控件的"InvokeRequired".
或者,您始终可以使用PInvoke检查当前线程是否与主线程不同.如果线程不同,则无需使用Invoke.如果您愿意,我可以共享该代码.

希望对您有所帮助!
Sevak is right! You can always use parent''s "InvokeRequired" if the control doesn''t have one...
Alternately you can always check if the current thread is different from the main thread using PInvoke. If the threads are different you need to use Invoke else not. If you want I can share the code for that.

Hope that helps!


这可能对您有帮助

This might be help you

this.BeginInvoke((ThreadStart)delegate()
 {

//UI change code goes here

});




谢谢




Thanks


这篇关于如何调用状态栏中的进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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