首页 课程资源 讲义     /    Winform进度条BackgroundWorker绝对不是官方例子

Winform进度条BackgroundWorker绝对不是官方例子

上传者: caikeyter | 上传时间:2024/4/20 19:27:33 | 文件大小:34KB | 文件类型:ZIP
Winform进度条BackgroundWorker绝对不是官方例子
在WinForm开发中,在处理大量数据时不免会有耗时较长的操作,如果将这些操作放在主线程里,软件界面会有较长时间的“无响应”,降低了用户体验,常用的解决方式是加上进度条。
实现思路--------------------------------------------------------------------------------使用BackgroundWorker(已经封装好的线程工具)控件在后台线程执行费时的操作,在主线程中打开一个进度条窗体显示进度。
实现步骤--------------------------------------------------------------------------------第0步:创建一个具有进度条的窗体,以显示进度新建窗体ProcessForm,设置属性FormBorderStyle为None,添加一个ProcessBar控件,如下图所示:进度条窗体PrcessBar的Style属性设置为MarQuee。
在ProcessForm添加如下公共属性:?1234567891011121314151617181920212223//////设置提示信息///publicstringMessageInfo{set{this.labelInfor.Text=value;}}//////设置进度条显示值///publicintProcessValue{set{this.progressBar1.Value=value;}}//////设置进度条样式///publicProgressBarStyleProcessStyle{set{this.progressBar1.Style=value;}}第1步:创建进度条管理类ProcessOperator在该类中添加如下字段:?12privateBackgroundWorker_backgroundWorker;//后台线程privateProcessForm_processForm;//进度条窗体添加如下公共属性、方法和事件:?123456789101112131415161718192021222324252627282930#region公共方法、属性、事件//////后台执行的操作///publicActionBackgroundWork{get;set;}//////设置进度条显示的提示信息///publicstringMessageInfo{set{_processForm.MessageInfo=value;}}//////后台任务执行完毕后事件///publiceventEventHandlerBackgroundWorkerCompleted;//////开始执行///publicvoidStart(){_backgroundWorker.RunWorkerAsync();_processForm.ShowDialog();}#endregion其中,属性BackgroundWork可以指向一个无参数的方法,这里(客户端代码)用来指向要在 本软件ID:4972684

文件下载

资源详情

[{"title":"(21个子文件34KB)Winform进度条BackgroundWorker绝对不是官方例子","children":[{"title":"ProcessDemo","children":[{"title":"ProcessDemo.sln <span style='color:#111;'>1.37KB</span>","children":null,"spread":false},{"title":"Process","children":[{"title":"Process.csproj <span style='color:#111;'>3.01KB</span>","children":null,"spread":false},{"title":"bin","children":[{"title":"Debug","children":null,"spread":false}],"spread":true},{"title":"ProcessForm.resx <span style='color:#111;'>5.68KB</span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"TempPE","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"ProcessForm.Designer.cs <span style='color:#111;'>3.87KB</span>","children":null,"spread":false},{"title":"PercentProcessOperator.cs <span style='color:#111;'>4.51KB</span>","children":null,"spread":false},{"title":"Class1.cs <span style='color:#111;'>159B</span>","children":null,"spread":false},{"title":"ProcessForm.cs <span style='color:#111;'>960B</span>","children":null,"spread":false},{"title":"ProcessOperator.cs.cs <span style='color:#111;'>3.28KB</span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"AssemblyInfo.cs <span style='color:#111;'>1.31KB</span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"ProcessDemo","children":[{"title":"bin","children":[{"title":"Debug","children":[{"title":"ProcessDemo.vshost.exe <span style='color:#111;'>13.99KB</span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"FormMain.cs <span style='color:#111;'>1.96KB</span>","children":null,"spread":false},{"title":"FormMain.Designer.cs <span style='color:#111;'>2.64KB</span>","children":null,"spread":false},{"title":"Program.cs <span style='color:#111;'>495B</span>","children":null,"spread":false},{"title":"obj","children":[{"title":"Debug","children":[{"title":"TempPE","children":null,"spread":false},{"title":"Refactor","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"FormMain.resx <span style='color:#111;'>5.68KB</span>","children":null,"spread":false},{"title":"ProcessDemo.csproj <span style='color:#111;'>3.86KB</span>","children":null,"spread":false},{"title":"Properties","children":[{"title":"Resources.resx <span style='color:#111;'>5.48KB</span>","children":null,"spread":false},{"title":"Settings.settings <span style='color:#111;'>249B</span>","children":null,"spread":false},{"title":"AssemblyInfo.cs <span style='color:#111;'>1.32KB</span>","children":null,"spread":false},{"title":"Settings.Designer.cs <span style='color:#111;'>1.07KB</span>","children":null,"spread":false},{"title":"Resources.Designer.cs <span style='color:#111;'>2.80KB</span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"ProcessDemo.suo <span style='color:#111;'>30.00KB</span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

  • zhang_88888888:
    真心的不错,非常简单且封闭的非常不错的一个实例。现已经用在项目中。2016-10-26
  • pepsi312:
    不错,封装的很好2016-08-23
  • kingwebo:
    很好的东东。很有用。2016-05-26
  • 岁月落寞忆流年:
    资源不错,封装的很好2016-05-11
  • 热带风味冰红茶:
    很好解决了我的大问题2015-10-25

免责申明

【好快吧下载】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【好快吧下载】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【好快吧下载】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,8686821#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明