Frm_UserProgress.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using OTSIncAReportApp.SysMgrTools;
  2. using System;
  3. using System.Collections;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace OTSIncAReportMailInterface
  7. {
  8. /// <summary>
  9. /// 进度条显示窗体
  10. /// </summary>
  11. public partial class Frm_UserProgress : Form
  12. {
  13. #region 全局变量
  14. private MyProgressBar m_mpbr;
  15. private Label m_l;
  16. #endregion
  17. #region 构造函数及窗体加载
  18. public Frm_UserProgress()
  19. {
  20. InitializeComponent();
  21. }
  22. private void Frm_UserProgress_SizeChanged(object sender, EventArgs e)
  23. {
  24. //progressBar1.Width = this.Width;
  25. }
  26. private void Frm_UserProgress_Load(object sender, EventArgs e)
  27. {
  28. m_mpbr = new MyProgressBar();
  29. m_mpbr.Parent = progressBar1;
  30. progressBar1.Width = this.Width;
  31. progressBar1.Height = this.Height;
  32. m_mpbr.Width = progressBar1.Width;
  33. m_mpbr.Height = progressBar1.Height;
  34. m_l = new Label();
  35. m_l.Parent = m_mpbr;
  36. m_l.BackColor = Color.Transparent;
  37. m_l.ForeColor = Color.SteelBlue;
  38. m_l.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  39. m_l.Width = m_mpbr.Width;
  40. m_l.Height = m_mpbr.Height;
  41. }
  42. #endregion
  43. #region 自定义方法封装
  44. /// <summary>
  45. /// 当前进度条,显示的进度值,及进度条上显示的文本信息
  46. /// </summary>
  47. /// <param name="in_value"></param>
  48. /// <param name="in_str"></param>
  49. public void SetProgressValueAndText(int in_value, string in_str)
  50. {
  51. if (m_mpbr != null)
  52. {
  53. //string str1 = "当前进度";
  54. //Language lan = new Language();
  55. //Hashtable table = lan.GetNameTable("Frm_UserProgress");
  56. //str1 = table["str1"].ToString();
  57. m_mpbr.Value = in_value;
  58. m_l.Text = m_mpbr.Value.ToString() + "%" + "(" + in_str + ")";
  59. this.Refresh();
  60. }
  61. }
  62. /// <summary>
  63. /// 获取当前进度条的当前进度值
  64. /// </summary>
  65. /// <returns></returns>
  66. public int GetProgressValue()
  67. {
  68. return m_mpbr.Value;
  69. }
  70. #endregion
  71. }
  72. #region 封装ProgressBar进度条类
  73. public class MyProgressBar : ProgressBar
  74. {
  75. public MyProgressBar()
  76. {
  77. base.SetStyle(ControlStyles.UserPaint, true);
  78. }
  79. protected override void OnPaint(PaintEventArgs e)
  80. {
  81. SolidBrush brush = null;
  82. Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
  83. bounds.Height -= 4;
  84. bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;
  85. brush = new SolidBrush(Color.SkyBlue);
  86. e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
  87. ControlPaint.DrawBorder(e.Graphics,
  88. this.ClientRectangle,
  89. Color.LightSteelBlue,
  90. 1,
  91. ButtonBorderStyle.Solid,
  92. Color.LightSteelBlue,
  93. 1,
  94. ButtonBorderStyle.Solid,
  95. Color.LightSteelBlue,
  96. 1,
  97. ButtonBorderStyle.Solid,
  98. Color.LightSteelBlue,
  99. 1,
  100. ButtonBorderStyle.Solid);
  101. }
  102. #endregion
  103. }
  104. }