• 进度条界面控件


    using Share;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Windows.Forms;
    
    namespace LUserControl
    {
        public partial class LProgressForm : Form
        {
            public LTranslucentForm translucentForm;
            /// <summary>
            /// 进度条进度事件,从小,到大的进度
            /// </summary>
            private Action<Action<int> , int,int> _ImplementAction;
            public int ipos = 0;
            public int Ipos
            {
                get { return this.progressBar.Value; }
            }
            public LProgressForm(Action<Action<int>, int, int> implementAction)
            {
                _ImplementAction = implementAction;
                InitializeComponent();
                this.progressBar.Maximum = 100;
            }
    
            public void SetProgressValue()
            {
                //this.progressBar.Value = value;
                this.Invoke(new Action(() =>
                {
                    this.progressBar.Value = Convert.ToInt32(ipos);
    
                }));
            }
    
            public void SetProgressValue(int value)
            {
                if (value > progressBar.Maximum)
                {
                    return;
                }
                System.Threading.Thread.Sleep(5);
                this.Invoke(new Action(() =>
                {
                    this.progressBar.Value = value;
                    //this.label1.Text = "Progress :" + value.ToString() + "%";
                }));
                // 这里关闭,比较好,呵呵!  
                //if (value == this.progressBar.Maximum - 1) this.Close();
            }
    
            private void ProgressForm_Load(object sender, EventArgs e)
            {
                Thread td = new Thread(QiDong);
                td.Start();
    
            }
    
            private void QiDong()
            {
                Thread.Sleep(1000);
                Updata();
            }
    
            public void Updata()
            {
                this.Invoke(new Action(() =>
                {
                    timer1.Enabled = true;
                }));
    
                _ImplementAction?.Invoke(proValue, 0, 98);
                SetProgressValue(98);
            }
    
            #region 进度
            public AutoResetEvent mRecvEvent;//接收信号量
    
    
            // 代理定义,可以在Invoke时传入相应的参数  
            private delegate void funHandle(int nValue);
            private funHandle myHandle = null;
            int nValue = 0;
            /// <summary>  
            /// 线程函数中调用的函数  
            /// </summary>  
            private void ShowProgressBar()
            {
                myHandle = new funHandle(SetProgressValue);
    
            }
            /// <summary>  
            /// 线程函数,用于处理调用  
            /// </summary>  
            private void ThreadFun()
            {
                //MethodInvoker mi = new MethodInvoker(ShowProgressBar);
                //this.BeginInvoke(mi);
                System.Threading.Thread.Sleep(1000); // sleep to show window  
                for (; nValue < 3000; ++nValue)
                {
                    System.Threading.Thread.Sleep(5);
                    LogHelp.WriteLog("进度:" + nValue);
                    //this.Invoke(this.myHandle, new object[] { (nValue / 30) });
                    SetProgressValue(nValue / 30);
                }
                mRecvEvent.Set();
    
    
            }
    
            private void proValue(int nValue = -1)
            {
                if (nValue == -1)
                {
                    nValue = this.progressBar.Value;
                    nValue++;
                }
                SetProgressValue(nValue);
            }
            #endregion
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (progressBar.Value < progressBar.Maximum)
                {
                    progressBar.Value++;
                }
                else
                {
                    //ProcessHelp.StartProcess(@"abc.exe", staffCardCode);
                    //Thread.Sleep(1000);
                    timer1.Enabled = false;
                    translucentForm.Focus();
                    this.Close();
                    translucentForm.Close();
                }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace LUserControl
    {
        public partial class LTranslucentForm : Form
        {
            public delegate void FocusHandle();
            private Action<Action<int>, int, int> _ImplementAction;
            public LTranslucentForm(Action<Action<int>, int, int> implementAction)
            {
                _ImplementAction = implementAction;
                InitializeComponent();
            }
    
            private void LTranslucentForm_Load(object sender, EventArgs e)
            {
                Updata();
            }
            public void Updata()
            {
                LProgressForm progressForm = new LProgressForm(_ImplementAction);
                progressForm.translucentForm = this;
                progressForm.ShowDialog();
                //progressForm.Updata();
    
            }
    
            private void LTranslucentForm_FormClosed(object sender, FormClosedEventArgs e)
            {
                
            }
        }
    }

    用法:

    using Share;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    
    namespace LUserControl.Progress
    {
        /// <summary>
        /// 更新登录界面类
        /// </summary>
        public class ProgressFuction
        {
            public static string PATH = @"D:xiangmuxiangmu.login";
            public static string ProcessName = @"Login";
            /// <summary>
            /// 进度控件回调事件
            /// </summary>
            /// <param name="action">进度向前事件</param>
            /// <param name="min">开始最小度数</param>
            /// <param name="max">结束最大度数</param>
            public static void Progress(Action<int> action, int min, int max)
            {
                string path = PATH + @".zip";
                try
                {
                    //解压,覆盖
                    FileHelp.UnZipFile(path, action, min, max);
    
                    //删除更新包
                    FileHelp.DeleteFile(path);
                }
                catch (Exception)
                {
                    throw;
                }
            }
    
            /// <summary>
            /// 检测登录界面是否更新
            /// </summary>
            public static void CheckLoginUpdate()
            {
                string path = PATH + @".zip";
                if (File.Exists(path))//判断文件是不是存在
                {
                    //杀掉登录界面
                    ProcessHelp.KillProcess(ProcessName);
                    //启动更新界面
                    LTranslucentForm progressForm = new LTranslucentForm(Progress);
                    
                    progressForm.ShowDialog();
    
                    ProcessHelp.StartProcess(@"D:xiangmuLogin.exe");
                    while (true)
                    {
                        //判断登录界面是否启动了,如果启动则跳出
                        if (ProcessHelp.IsProcess(ProcessName))
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
  • 相关阅读:
    STL中的stack(堆栈)
    单链表的创建与删除
    面试题四 从尾到头打印链表
    第 1 章 第 2 题 空间敏感排序问题 位向量实现( bitset位向量 )
    第 1 章 第 2 题 位向量的数组实现问题 位运算实现
    第 1 章 第 1 题 高级语言的排序问题 C++标准算法实现
    面试题三 替换空格
    面试题二 二维数组中的查找
    面试题一 赋值运算符函数
    不为客户连接创建子进程的并发回射服务器( poll实现 )
  • 原文地址:https://www.cnblogs.com/lsgsanxiao/p/9020549.html
Copyright © 2020-2023  润新知