Implementation of a progress bar

2010-10-28  来源:本站原创  分类:DotNet  人气:123 

Create a new class MyProcessBar

internal class MyProcessBar
    {
        private frmProcessBar myProcessBar = null;// Progress bar form event
        private delegate bool IncreaseHandle(int nValue);// Declare a delegate
        private IncreaseHandle myIncrease = null;// Define a delegate variable
        public MyProcessBar()
        {

        }
        /// <summary>
        ///  Open the progress bar form
        /// </summary>
        private void ShowProcessBar()
        {
            myProcessBar = new frmProcessBar();
            //  Binding events
            myIncrease = new IncreaseHandle(myProcessBar.Increase);
            myProcessBar.ShowDialog();
            myProcessBar = null;
        }
        /// <summary>
        ///  Thread function
        /// </summary>
        private void ThreadFun(object o)
        {
            Form fm = (Form)o;
            // Declare a delegate, the delegate to be ShowProcessBar managed code  , Must be a  void
            MethodInvoker mi = new MethodInvoker(ShowProcessBar);
            // Asynchronous calls  ShowProcessBar( Don't have to wait after you perform ShowProcessBar method  , The program can execute down  )
            fm.BeginInvoke(mi);
            Thread.Sleep(1000);// The thread to stop a sec, let the progress bar shows the form
            bool blnIncreased = false;
            object objReturn = null;
            do
            {
                Thread.Sleep(50);
                // Synchronous calls  myProcessBar.Increase(), The program has to wait for the method completes, you can perform down
                objReturn = fm.Invoke(this.myIncrease,
              new object[] { 2 });
                blnIncreased = (bool)objReturn;
            }
            while (blnIncreased);
        }

        /// <summary>
        ///  Thread start
        /// </summary>
        /// <param name="o"></param>
        public void Start(object o)
        {
            Thread thdSub = new Thread(ThreadFun);
            thdSub.IsBackground = true;
            thdSub.Start(o);
        }
    }

Create a new form frmProcessBar (progress bar form) Add ProcessBar control

Implementation of a progress bar

public partial class frmProcessBar : Form
    {
        public frmProcessBar()
        {
            InitializeComponent();
        }
        private void frmProcessBar_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// Increase process bar
        /// </summary>
        /// <param name="nValue">the value increased</param>
        /// <returns></returns>
        public bool Increase(int nValue)
        {
            if (nValue > 0)
            {
                if (prcBar.Value + nValue < prcBar.Maximum)
                {
                    prcBar.Value += nValue;
                    return true;
                }
                else
                {
                    prcBar.Value = prcBar.Maximum;
                    this.Close();
                    return false;
                }
            }
            return false;
        }
    }

Main window

private void btnStart_Click(object sender, EventArgs e)
        {
            MyProcessBar pb = new MyProcessBar();
            pb.Start(this);
        }

相关文章
  • Implementation of a progress bar 2010-10-28

    Create a new class MyProcessBar internal class MyProcessBar { private frmProcessBar myProcessBar = null;// Progress bar form event private delegate bool IncreaseHandle(int nValue);// Declare a delegate private IncreaseHandle myIncrease = null;// Defi

  • Implementation of the progress bar 2010-12-12

    Details refer to Annex. Sample Chart:

  • JavaScript source code examples of the progress bar design 2010-05-05

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Progress bar </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTEN

  • [Transfer] javacsript progress bar source 2010-10-17

    <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> Progress bar </ TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author&q

  • (To) swing the progress bar 2011-05-06

    package com.view; import java.awt.Dialog; import java.awt.Frame; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import jav

  • ajax upload progress bar implementation 2010-11-25

    Mainly through UploadListener monitor how many bytes the server received, returned to the client, the javascript, div, css progress bar display to operate public class UploadListener implements OutputStreamListener { private HttpServletRequest reques

  • ext2.2 + struts2.0 upload progress bar 2008-05-03

    The first step: js part of the code var fp = new Ext.FormPanel({ fileUpload : true, width : 400, frame : true, title : ' Upload a picture ', autoHeight : true, bodyStyle : 'padding: 10px 10px 0 10px;', labelWidth : 50, url : 'uploadController?t=' + n

  • Achieved using jsp progress bar 2010-04-13

    Development of regional marketing base station maintenance module, the data inspection involves examination of many aspects, because the implementation of more than 20 sql, so need to wait for a very long time to return, use the one written in PHP be

  • Achieved with a progress bar jsp 2010-03-15

    Development of regional marketing base maintenance module, the data check various aspects related to the inspection, because the implementation of more than 20 sql, so they need to wait a long time to return to the use of PHP in the written prior to

  • Music of the progress bar - Custom 2010-04-11

    The progress bar music [Premise] * Android itself provides the interface seems to be: MediaController seen the screenshots, but found it a very ugly today, wrote out a share of you are sharing in [Requirements] 1. Progress bar control is going to use

  • Progress bar (ProgressBar) drag section (SeekBar) android 2010-07-12

    This article from http://www.cnblogs.com/TerryBlog/archive/2010/06/17/1759542.html Progress bar (ProgressBar) When an application in the background, the front interface is not changed, but since Android configuration different from the models, and so

  • Achieve progress bar 2010-07-27

    Is a measure of user experience has been key to the success of a project. In some treatment processing time may be a long process in the progress bar to the user experience will be well received than the 1: iframe from action target = point to a ifra

  • android ----> progress bar (ProgressBar) 2010-11-19

    When an application in the background, the front interface is not what information, when users do not know whether the procedures in the implementation, implementation progress, whether the application has encountered an error termination, then the n

  • Android progress bar 2010-12-24

    Progress bar (ProgressBar) When an application in the background, the front interface will not produce changes, but because Android configuration of the different models, and sometimes the process of implementation of the program users do not know wh

  • One study notes ---- BlackBerry progress bar 2011-05-25

    Suddenly want to own the company recently migrated to the BlackBerry up the project, because they have heard very little app for BlackBerry, and BlackBerry development of seemingly more complicated, as the convenience of android and iPhone, anyway, n

  • Jsp | Ajax + fileupload + json + servlet by many file upload progress bar shows 2009-04-02

    Sales: Jsp | Ajax + fileupload + json + servlet by many file upload progress bar shows demo video and screenshots download 7.55M: Download 1: mail.qq.com / cgi-bin / ftnExs_download Download 2 (javaEye): http://celerity.javaeye.com/topics/download/d1

  • Progress bar shows Ajax_ 2009-08-04

    JSP part: <% @ Page language = "java" import = "java.util .*" pageEncoding = "gbk"%> <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN"> <html> <head> <title> My J

  • 2010.02.03 (2) - jquery ajax to add a progress bar as well as the relative positioning and absolute positioning 2010-03-29

    2010.02.03 (2) - jquery ajax to add a progress bar as well as the relative positioning and absolute positioning relative positioning: #loading { position: relative; left: 30px; top: 20px; } absolute positioning: #loading { position: absolute; left: 3

  • Share ProgressMonitorInputStream of usage - the progress bar shows 2010-03-29

    Summary ProgressMonitorInputStream the usage is as follows: import java.io.FileInputStream; import javax.swing.ProgressMonitor; import javax.swing.ProgressMonitorInputStream; public class ProgressMonitorTest ( public static void main (String args [])

  • Control.ProgressBar percentage-based progress bar. 2010-03-30

    Control.ProgressBar is a use of Prototype development, based on the percentage of progress bar. I tried it is still quite good use. Source code is as follows: <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="te