欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#中數(shù)據(jù)的傳遞以及ToolStripProgressBar

 更新時(shí)間:2016年11月18日 17:00:12   作者:可達(dá)鴨要進(jìn)化  
本文主要介紹了C#的數(shù)據(jù)傳遞方法以及ToolStripProgressBar進(jìn)度條的使用。希望對(duì)大家有所幫助,話不多說,請(qǐng)看下面代碼

代碼:

方法一:窗體的代碼-->可以直接通過預(yù)設(shè)的Click事件來實(shí)現(xiàn)控制進(jìn)度條。

public partial class Form1 : Form
 { 
  public Form1()
  {
   InitializeComponent();
   toolStripProgressBar_save.Minimum = 0;
   toolStripProgressBar_save.Maximum = 100;
   toolStripProgressBar_save.Step = 5;
  }
  #region 不涉及數(shù)據(jù)傳輸
  private void button_10_Click(object sender, EventArgs e)
  {
   //清空進(jìn)度表
   toolStripProgressBar_save.Value = 0;
   if(toolStripProgressBar_save.Value<10)
   {
    for (int i=0;i<2;i++)
    {
     toolStripProgressBar_save.PerformStep();
     toolStripLabel_save.Text = toolStripProgressBar_save.Value.ToString() + "%";
    }
   }
  }
  private void button_30_Click(object sender, EventArgs e)
  {
   if (toolStripProgressBar_save.Value < 30)
   {
    for(int i=0;i<4;i++)
    {
     toolStripProgressBar_save.PerformStep();
    }
   }
   toolStripLabel_save.Text = "30%";
  }
  private void button_50_Click(object sender, EventArgs e)
  {
   if (toolStripProgressBar_save.Value < 50)
   {
    for (int i = 0; i < 4; i++)
    {
     toolStripProgressBar_save.PerformStep();
    }
   }
   toolStripLabel_save.Text = "50%";
  }
  private void button_60_Click(object sender, EventArgs e)
  {
   if (toolStripProgressBar_save.Value < 60)
   {
    for (int i = 0; i < 2; i++)
    {
     toolStripProgressBar_save.PerformStep();
    }
   }
   toolStripLabel_save.Text = "60%";
  }
  private void button_80_Click(object sender, EventArgs e)
  {
   if (toolStripProgressBar_save.Value < 80)
   {
    for (int i = 0; i < 4; i++)
    {
     toolStripProgressBar_save.PerformStep();
    }
   }
   toolStripLabel_save.Text = "80%";
  }
  private void button_100_Click(object sender, EventArgs e)
  {
   if (toolStripProgressBar_save.Value < 100)
   {
    for (int i = 0; i < 4; i++)
    {
     toolStripProgressBar_save.PerformStep();
    }    
   }
   toolStripLabel_save.Text = "Complete!";
  }
  #endregion
  private void button_save_Click(object sender, EventArgs e)
  {
   Save.Singleton().SaveAll();
  }
 }

方法二:通過調(diào)用其他類里的方法來實(shí)現(xiàn)對(duì)進(jìn)度條的控制。

注意一:需要using System.Windows.Forms;

注意二:進(jìn)度條ToolStripProgressBar的權(quán)限需要改成Public

public class Save
 {
  private static Save _instance = null;
  private Form1 n = null;
  public void SaveAll()
  {
   getWnd();
   n.toolStripProgressBar_save.Minimum = 0;
   n.toolStripProgressBar_save.Maximum = 100;
   //清空進(jìn)度表
   n.toolStripProgressBar_save.Value = 0;
   n.toolStripProgressBar_save.Step = 5;
   #region 保存過程-與單獨(dú)按鈕是一樣的
   if (n.toolStripProgressBar_save.Value < 10)
   {   
    for (int i = 0; i < 2; i++)
    {
     n.toolStripProgressBar_save.PerformStep();
     n.toolStripLabel_save.Text = n.toolStripProgressBar_save.Value.ToString() + "%";
    }
   }
   Thread.Sleep(1000);
   if (n.toolStripProgressBar_save.Value < 30)
   {
    for (int i = 0; i < 4; i++)
    {
     n.toolStripProgressBar_save.PerformStep();
     n.toolStripLabel_save.Text = n.toolStripProgressBar_save.Value.ToString()+"%";
    }
   }
   Thread.Sleep(100);
   if (n.toolStripProgressBar_save.Value < 50)
   {
    for (int i = 0; i < 4; i++)
    {
     n.toolStripProgressBar_save.PerformStep();
     n.toolStripLabel_save.Text = n.toolStripProgressBar_save.Value.ToString() + "%";
    }
   }
   Thread.Sleep(100);
   if (n.toolStripProgressBar_save.Value < 60)
   {
    for (int i = 0; i < 2; i++)
    {
     n.toolStripProgressBar_save.PerformStep();
     n.toolStripLabel_save.Text = n.toolStripProgressBar_save.Value.ToString() + "%";
    }
   }
   Thread.Sleep(100);
   if (n.toolStripProgressBar_save.Value < 80)
   {
    for (int i = 0; i < 4; i++)
    {
     n.toolStripProgressBar_save.PerformStep();
     n.toolStripLabel_save.Text = n.toolStripProgressBar_save.Value.ToString() + "%";
    }
   }
   Thread.Sleep(100);
   if (n.toolStripProgressBar_save.Value < 100)
   {
    for (int i = 0; i < 4; i++)
    {
     n.toolStripProgressBar_save.PerformStep();
     n.toolStripLabel_save.Text = n.toolStripProgressBar_save.Value.ToString() + "%";
    }
   }
   n.toolStripLabel_save.Text = "Complete!";
   Thread.Sleep(100);
   #endregion
  }
  //查找當(dāng)前打開的窗體,必須有這個(gè)才能傳遞數(shù)據(jù)
  private void getWnd()
  {
   foreach(Form fm in Application.OpenForms)
   {
    if (fm.Name == "Form1")
    {
     n = (Form1)fm;
     break;
    }
   }
  }
  public static Save Singleton()
  {
   if (_instance == null)
   {
    _instance = new Save();
   }
   return _instance;
  }
 }

 

效果圖:(左邊為方法一的效果、右邊為方法二的效果圖)

   

相關(guān)文章

最新評(píng)論