using OTSIncAReportApp.SysMgrTools;
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
namespace OTSIncAReportMailInterface
{
    /// 
    /// 进度条显示窗体
    /// 
    public partial class Frm_UserProgress : Form
    {
        #region 全局变量
        private MyProgressBar m_mpbr;
        private Label m_l;
        #endregion
        #region 构造函数及窗体加载
        public Frm_UserProgress()
        {
            InitializeComponent();
        }
        private void Frm_UserProgress_SizeChanged(object sender, EventArgs e)
        {
            //progressBar1.Width = this.Width;
        }
        private void Frm_UserProgress_Load(object sender, EventArgs e)
        {
            m_mpbr = new MyProgressBar();
            m_mpbr.Parent = progressBar1;
            progressBar1.Width = this.Width;
            progressBar1.Height = this.Height;
            m_mpbr.Width = progressBar1.Width;
            m_mpbr.Height = progressBar1.Height;
            m_l = new Label();
            m_l.Parent = m_mpbr;
            m_l.BackColor = Color.Transparent;
            m_l.ForeColor = Color.SteelBlue;
            m_l.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            m_l.Width = m_mpbr.Width;
            m_l.Height = m_mpbr.Height;
        }
        #endregion
        #region 自定义方法封装
        /// 
        /// 当前进度条,显示的进度值,及进度条上显示的文本信息
        /// 
        /// 
        /// 
        public void SetProgressValueAndText(int in_value, string in_str)
        {
            if (m_mpbr != null)
            {
                string str1 = "当前进度";
                Language lan = new Language();
                Hashtable table = lan.GetNameTable("Frm_UserProgress");
                str1 = table["str1"].ToString();
                m_mpbr.Value = in_value;
                m_l.Text = str1 + m_mpbr.Value.ToString() + "%" + "(" + in_str + ")";
                this.Refresh();
            }
        }
        /// 
        /// 获取当前进度条的当前进度值
        /// 
        /// 
        public int GetProgressValue()
        {
            return m_mpbr.Value;
        }
        #endregion
    }
    #region 封装ProgressBar进度条类
    public class MyProgressBar : ProgressBar
    {
        public MyProgressBar()
        {
            base.SetStyle(ControlStyles.UserPaint, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            SolidBrush brush = null;
            Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
            bounds.Height -= 4;
            bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;
            brush = new SolidBrush(Color.SkyBlue);
            e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
            ControlPaint.DrawBorder(e.Graphics,
                    this.ClientRectangle,
                    Color.LightSteelBlue,
                    1,
                    ButtonBorderStyle.Solid,
                    Color.LightSteelBlue,
                    1,
                    ButtonBorderStyle.Solid,
                    Color.LightSteelBlue,
                    1,
                    ButtonBorderStyle.Solid,
                    Color.LightSteelBlue,
                    1,
                    ButtonBorderStyle.Solid);
        }
        #endregion
    }
}