c# – 更新状态栏文本
发布时间:2020-12-16 01:57:01 所属栏目:百科 来源:网络整理
导读:这是最简单的事情,但我不能更新状态栏上的文字…我刚开始在c#工作,但找不到解决方案.. 在所有答案中,接受的答案是statusBar1.Text =“text”; 我做了简单的菜单,并在菜单中添加了LOAD项目.图片已加载,一切正常,只是状态文本不更新… 顺便说一下,MessageBox还
这是最简单的事情,但我不能更新状态栏上的文字…我刚开始在c#工作,但找不到解决方案..
在所有答案中,接受的答案是statusBar1.Text =“text”; 我做了简单的菜单,并在菜单中添加了LOAD项目.图片已加载,一切正常,只是状态文本不更新… 顺便说一下,MessageBox还会在状态栏中显示我需要的正确文本. 这是我的代码,它只是不起作用: private void menuLoad_Click(object sender,EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Load Photo"; dlg.Filter = "jpg files (*.jpg)" + "|*.jpg|All files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { try { statusBar1.Text = "Loading " + dlg.FileName; pbxPhoto.Image = new Bitmap(dlg.OpenFile()); statusBar1.Text = "Loaded " + dlg.FileName; MessageBox.Show("Text = " + dlg.FileName); } catch (Exception ex) { statusBar1.Text = "Unable to load file " + dlg.FileName; MessageBox.Show("Unable to load file: " + ex.Message); } } dlg.Dispose(); } 解决方法
也许文本被设置但是没有被绘制,因为你的线程忙于加载图片?您可以尝试强制状态栏使自身无效并重新绘制:
statusBar1.Text = "Loading " + dlg.FileName; statusBar1.Invalidate(); statusBar1.Refresh(); pbxPhoto.Image = new Bitmap(dlg.OpenFile()); statusBar1.Text = "Loaded " + dlg.FileName; statusBar1.Invalidate(); statusBar1.Refresh(); MessageBox.Show("Text = " + dlg.FileName); 实际上我想我会把它封装成一个方法,如下所示: private void UpdateStatusBarText(string text) { statusBar1.Text = text; statusBar1.Invalidate(); statusBar1.Refresh(); } 这样你的try块看起来像这样: UpdateStatusBarText("Loading " + dlg.FileName); pbxPhoto.Image = new Bitmap(dlg.OpenFile()); UpdateStatusBarText("Loaded " + dlg.FileName); MessageBox.Show("Text = " + dlg.FileName); 编辑 StatusStrip控件是一个容器控件.向其中添加ToolStripStatusLabel项,并更改该控件的文本而不是statusBar1的文本: private void UpdateStatusBarText(string text) { toolStripStatusLabel1.Text = text; statusBar1.Invalidate(); statusBar1.Refresh(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- iphone – ARC语义问题:没有可见的@interface for Class声
- reactjs – 如何在客户端和服务器端呈现逻辑上将react-rout
- 几个 Swift 代码规范
- Flutter:获取print()语句的行号,Android Studio
- swift – 领域移动平台,离线时如何连接?
- LibLinear使用总结(L1,L2正则)
- ruby-on-rails – 在rspec-rails中,assign做了什么?
- ruby-on-rails – 在Ruby on Rails 3应用程序中开始使用Web
- Vue异步组件处理路由组件加载状态的解决方案
- 优酷、土豆、56获取视频截图和标题和播放swf代码