首页 > 开发 > 综合 > 正文

C#中使用进度条

2024-07-21 02:26:24
字体:
来源:转载
供稿:网友

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.diagnostics;
using system.threading;
namespace windowsapplication2
{
 /// <summary>
 /// form1 的摘要说明。
 /// </summary>
 public class form1 : system.windows.forms.form
 {
  private system.windows.forms.button button1;
  private system.windows.forms.progressbar progressbar1;
  private system.windows.forms.progressbar progressbar2;
  private system.windows.forms.textbox textbox1;
  private system.windows.forms.textbox textbox2;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private system.componentmodel.container components = null;

  public form1()
  {
   //
   // windows 窗体设计器支持所必需的
   //
   initializecomponent();

   //
   // todo: 在 initializecomponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.dispose();
    }
   }
   base.dispose( disposing );
  }

  #region windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void initializecomponent()
  {
   this.button1 = new system.windows.forms.button();
   this.progressbar1 = new system.windows.forms.progressbar();
   this.progressbar2 = new system.windows.forms.progressbar();
   this.textbox1 = new system.windows.forms.textbox();
   this.textbox2 = new system.windows.forms.textbox();
   this.suspendlayout();
   //
   // button1
   //
   this.button1.location = new system.drawing.point(160, 184);
   this.button1.name = "button1";
   this.button1.tabindex = 1;
   this.button1.text = "button1";
   this.button1.click += new system.eventhandler(this.button1_click);
   //
   // progressbar1
   //
   this.progressbar1.enabled = false;
   this.progressbar1.location = new system.drawing.point(32, 16);
   this.progressbar1.name = "progressbar1";
   this.progressbar1.size = new system.drawing.size(336, 32);
   this.progressbar1.tabindex = 2;
   //
   // progressbar2
   //
   this.progressbar2.location = new system.drawing.point(32, 72);
   this.progressbar2.name = "progressbar2";
   this.progressbar2.size = new system.drawing.size(328, 24);
   this.progressbar2.tabindex = 3;
   //
   // textbox1
   //
   this.textbox1.location = new system.drawing.point(48, 136);
   this.textbox1.name = "textbox1";
   this.textbox1.tabindex = 4;
   this.textbox1.text = "100";
   //
   // textbox2
   //
   this.textbox2.location = new system.drawing.point(216, 136);
   this.textbox2.name = "textbox2";
   this.textbox2.tabindex = 5;
   this.textbox2.text = "100";
   //
   // form1
   //
   this.autoscalebasesize = new system.drawing.size(6, 14);
   this.backcolor = system.drawing.systemcolors.desktop;
   this.clientsize = new system.drawing.size(408, 222);
   this.controls.add(this.textbox2);
   this.controls.add(this.textbox1);
   this.controls.add(this.progressbar2);
   this.controls.add(this.progressbar1);
   this.controls.add(this.button1);
   this.name = "form1";
   this.text = "form1";
   this.resumelayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [stathread]
  static void main()
  {
   application.run(new form1());
  }

  private void button1_click(object sender, system.eventargs e)
  {
    int outloop = int32.parse(textbox1.text);
    int innerloop = int32.parse(textbox2.text);

   for (int i=1;i<=outloop;i++)
   {
    for (int j=i;j<=innerloop;j++)
    {
     if (j%10 == 0)
     {
      progressbar2.value = j;
      thread.sleep(100);
     }
    }
    progressbar1.value = i;
   }
  }
 }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表