⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progress.cs

📁 对ima、imz压缩文件修改
💻 CS
📖 第 1 页 / 共 3 页
字号:
        public void SetRange_Primary(int minimum, int maximum)
        {
            initEvent.WaitOne();
            Invoke(new RangeInvoker(DoSetRange_Primary), new object[] { minimum, maximum });
        }
        /// <summary>
        /// Call this method from the worker thread to increase the progress counter by a specified value.
        /// </summary>
        /// <param name="val">The amount by which to increment the progress indicator</param>
        public void Increment_Primary(int val)
        {
            Invoke(new IncrementInvoker(DoIncrement), new object[] { val });
        }
        /// <summary>
        /// Call this method from the worker thread to step the progress meter to a particular value.
        /// </summary>
        /// <param name="val"></param>
        public void StepTo_Primary(int val)
        {
            Invoke(new StepToInvoker(DoStepTo), new object[] { val });
        }

        /// <summary>
        /// Call this method from the worker thread to reset the range in the progress callback
        /// for the secondary progressbar
        /// </summary>
        /// <param name="minimum">The minimum value in the progress range (e.g. 0)</param>
        /// <param name="maximum">The maximum value in the progress range (e.g. 100)</param>
        /// <remarks>You must have called one of the Begin() methods prior to this call.</remarks>
        public void SetRange_Secondary(int minimum, int maximum)
        {
            initEvent.WaitOne();
            Invoke(new RangeInvoker(DoSetRange_Secondary), new object[] { minimum, maximum });
        }
        /// <summary>
        /// Call this method from the worker thread to increase the progress counter by a specified value.
        /// </summary>
        /// <param name="val">The amount by which to increment the progress indicator</param>
        public void Increment_Secondary(int val)
        {
            Invoke(new IncrementInvoker(DoIncrement_Secondary), new object[] { val });
        }
        /// <summary>
        /// Call this method from the worker thread to step the progress meter to a particular value.
        /// </summary>
        /// <param name="val"></param>
        public void StepTo_Secondary(int val)
        {
            Invoke(new StepToInvoker(DoStepTo_Secondary), new object[] { val });
        }

        /// <summary>
        /// If this property is true, then you should abort work
        /// </summary>
        public bool IsAborting
        {
            get { return abortEvent.WaitOne(0, false); }
        }
        public bool IsInitialized
        {
            get { return initialized; }
        }
        public int Stages { get { return 2; } }
        #endregion

        #region Implementation members invoked on the owner thread
        private void DoBegin()
        {
            titleRoot = Text;
            cancelButton.Enabled = true;
            ControlBox = true;
            initialized = true;
        }
        private void DoBegin(int minimum, int maximum)
        {
            DoBegin();
            DoSetRange_Primary(minimum, maximum);
        }
        private void DoBegin(bool AllowCancel)
        {
            titleRoot = Text;
            cancelButton.Enabled = AllowCancel;
            cancelButton.Visible = AllowCancel;
            ControlBox = AllowCancel;
            prgPrimary.Width = (AllowCancel ? 192 : 273);
            prgSecondary.Width = prgPrimary.Width;
            initialized = true;
        }

        private void DoEnd()
        {
            Close();
        }

        private void DoSetText(String text)
        {
            label.Text = text;
        }
        private void DoSetCaption(String text)
        {
            this.Text = text;
            titleRoot = Text;
        }

        private void DoSetRange_Primary(int minimum, int maximum)
        {
            prgPrimary.Minimum = minimum;
            prgPrimary.Maximum = maximum;
            prgPrimary.Value = minimum;
        }
        private void DoIncrement(int val)
        {
            if (prgPrimary.Value < prgPrimary.Maximum)
            {
                if (val <= (prgPrimary.Maximum - prgPrimary.Value))  //If incrementing by val won't push us past the max
                    prgPrimary.Increment(val);
                else
                    prgPrimary.Value = prgPrimary.Maximum; //Otherwise, just set it to the max
            }
            UpdateStatusText();
        }
        private void DoStepTo(int val)
        {
            if (val < prgPrimary.Maximum) { prgPrimary.Value = val; }
            UpdateStatusText();
        }

        private void DoSetRange_Secondary(int minimum, int maximum)
        {
            prgSecondary.Minimum = minimum;
            prgSecondary.Maximum = maximum;
            prgSecondary.Value = minimum;
        }
        private void DoIncrement_Secondary(int val)
        {
            if (prgSecondary.Value < prgSecondary.Maximum)
            {
                if (val <= (prgSecondary.Maximum - prgSecondary.Value))  //If incrementing by val won't push us past the max
                    prgSecondary.Increment(val);
                else
                    prgSecondary.Value = prgSecondary.Maximum; //Otherwise, just set it to the max
            }
        }
        private void DoStepTo_Secondary(int val) { if (val < prgSecondary.Maximum) { prgSecondary.Value = val; } }
        #endregion

        #region Overrides
        /// <summary>
        /// Handles the form load, and sets an event to ensure that
        /// intialization is synchronized with the appearance of the form.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            ControlBox = false;
            initEvent.Set();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        /// <summary>Handler for 'Close' clicking</summary>
        /// <param name="e"></param>
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            requiresClose = false;
            AbortWork();
            base.OnClosing(e);
        }
        #endregion

        #region Implementation Utilities
        /// <summary>Utility function that formats and updates the title bar text</summary>
        private void UpdateStatusText() { Text = titleRoot + String.Format(" - {0}% complete", (prgPrimary.Value * 100) / (prgPrimary.Maximum - prgPrimary.Minimum)); }
        private void cancelButton_Click(object sender, EventArgs e) { AbortWork(); }

        /// <summary>Utility function to terminate the thread</summary>
        private void AbortWork()
        {
            titleRoot = "Aborting: " + titleRoot;
            this.cancelButton.Enabled = false;
            this.cancelButton.Text = "Cancelling";
            abortEvent.Set();
        }
        #endregion

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.prgPrimary = new System.Windows.Forms.ProgressBar();
            this.label = new System.Windows.Forms.Label();
            this.cancelButton = new System.Windows.Forms.Button();
            this.prgSecondary = new System.Windows.Forms.ProgressBar();
            this.SuspendLayout();
            // 
            // prgPrimary
            // 
            this.prgPrimary.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this.prgPrimary.Location = new System.Drawing.Point(11, 76);
            this.prgPrimary.Name = "prgPrimary";
            this.prgPrimary.Size = new System.Drawing.Size(196, 23);
            this.prgPrimary.TabIndex = 1;
            // 
            // label
            // 
            this.label.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.label.Location = new System.Drawing.Point(8, 8);
            this.label.Name = "label";
            this.label.Size = new System.Drawing.Size(276, 64);
            this.label.TabIndex = 0;
            this.label.Text = "Starting operation...";
            // 
            // cancelButton
            // 
            this.cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Right;
            //            this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.cancelButton.Enabled = false;
            this.cancelButton.Location = new System.Drawing.Point(213, 89);
            this.cancelButton.Name = "cancelButton";
            this.cancelButton.Size = new System.Drawing.Size(75, 23);
            this.cancelButton.TabIndex = 3;
            this.cancelButton.Text = "Cancel";
            this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
            // 
            // prgSecondary
            // 
            this.prgSecondary.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this.prgSecondary.Location = new System.Drawing.Point(11, 105);
            this.prgSecondary.Name = "prgSecondary";
            this.prgSecondary.Size = new System.Drawing.Size(196, 23);
            this.prgSecondary.TabIndex = 2;
            // 
            // TwoStageProgressWindow
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(294, 138);
            this.Controls.Add(this.prgSecondary);
            this.Controls.Add(this.cancelButton);
            this.Controls.Add(this.prgPrimary);
            this.Controls.Add(this.label);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "TwoStageProgressWindow";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Two Stage ProgressWindow";
            this.ResumeLayout(false);

        }
        #endregion

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -