You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.ComponentModel;
  5. using HKCardManager.UserPages;
  6. namespace HKCardManager
  7. {
  8. /// <summary>
  9. /// 自定义控件:半透明控件
  10. /// </summary>
  11. /*
  12. * [ToolboxBitmap(typeof(MyOpaqueLayer))]
  13. * 用于指定当把你做好的自定义控件添加到工具栏时,工具栏显示的图标。
  14. * 正确写法应该是
  15. * [ToolboxBitmap(typeof(XXXXControl),"xxx.bmp")]
  16. * 其中XXXXControl是你的自定义控件,"xxx.bmp"是你要用的图标名称。
  17. */
  18. [ToolboxBitmap(typeof(MyOpaqueLayer))]
  19. public class MyOpaqueLayer : System.Windows.Forms.Control
  20. {
  21. private bool _transparentBG = true;//是否使用透明
  22. private int _alpha = 125;//设置透明度
  23. private System.ComponentModel.Container components = new System.ComponentModel.Container();
  24. public MyOpaqueLayer()
  25. : this(125, true)
  26. {
  27. }
  28. public MyOpaqueLayer(int Alpha, bool IsShowLoadingImage)
  29. {
  30. SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);
  31. base.CreateControl();
  32. this._alpha = Alpha;
  33. if (IsShowLoadingImage)
  34. {
  35. PictureBox pictureBox_Loading = new PictureBox();
  36. pictureBox_Loading.BackColor = System.Drawing.Color.White;
  37. pictureBox_Loading.Image = global::HKCardManager.Properties.Resources.loading;
  38. pictureBox_Loading.Name = "pictureBox_Loading";
  39. pictureBox_Loading.Size = new System.Drawing.Size(48, 48);
  40. pictureBox_Loading.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
  41. Point Location = new Point(this.Location.X + (this.Width - pictureBox_Loading.Width) / 2, this.Location.Y + (this.Height - pictureBox_Loading.Height) / 2);//居中
  42. pictureBox_Loading.Location = Location;
  43. pictureBox_Loading.Anchor = AnchorStyles.None;
  44. this.Controls.Add(pictureBox_Loading);
  45. }
  46. }
  47. protected override void Dispose(bool disposing)
  48. {
  49. if (disposing)
  50. {
  51. if (!((components == null)))
  52. {
  53. components.Dispose();
  54. }
  55. }
  56. base.Dispose(disposing);
  57. }
  58. private SolidBrush fontBrush = new SolidBrush(Color.FromArgb(206, 94, 94, 94));
  59. /// <summary>
  60. /// 自定义绘制窗体
  61. /// </summary>
  62. /// <param name="e"></param>
  63. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  64. {
  65. float vlblControlWidth;
  66. float vlblControlHeight;
  67. Pen labelBorderPen;
  68. SolidBrush labelBackColorBrush;
  69. if (_transparentBG)
  70. {
  71. Color drawColor = Color.FromArgb(this._alpha, this.BackColor);
  72. labelBorderPen = new Pen(drawColor, 0);
  73. labelBackColorBrush = new SolidBrush(drawColor);
  74. }
  75. else
  76. {
  77. labelBorderPen = new Pen(this.BackColor, 0);
  78. labelBackColorBrush = new SolidBrush(this.BackColor);
  79. }
  80. base.OnPaint(e);
  81. vlblControlWidth = this.Size.Width;
  82. vlblControlHeight = this.Size.Height;
  83. e.Graphics.DrawRectangle(labelBorderPen, 0, 0, vlblControlWidth, vlblControlHeight);
  84. e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, vlblControlWidth, vlblControlHeight);
  85. e.Graphics.DrawString("Excel人员批量导入中...\n请勿操作制卡终端!!!", new Font("黑体", 20, FontStyle.Bold), fontBrush, vlblControlWidth / 2 - 120, vlblControlHeight / 2 + 40);
  86. }
  87. protected override CreateParams CreateParams//v1.10
  88. {
  89. get
  90. {
  91. CreateParams cp = base.CreateParams;
  92. cp.ExStyle |= 0x00000020; //0x20; // 开启 WS_EX_TRANSPARENT,使控件支持透明
  93. return cp;
  94. }
  95. }
  96. /*
  97. * [Category("myOpaqueLayer"), Description("是否使用透明,默认为True")]
  98. * 一般用于说明你自定义控件的属性(Property)。
  99. * Category用于说明该属性属于哪个分类,Description自然就是该属性的含义解释。
  100. */
  101. [Category("MyOpaqueLayer"), Description("是否使用透明,默认为True")]
  102. public bool TransparentBG
  103. {
  104. get
  105. {
  106. return _transparentBG;
  107. }
  108. set
  109. {
  110. _transparentBG = value;
  111. this.Invalidate();
  112. }
  113. }
  114. [Category("MyOpaqueLayer"), Description("设置透明度")]
  115. public int Alpha
  116. {
  117. get
  118. {
  119. return _alpha;
  120. }
  121. set
  122. {
  123. _alpha = value;
  124. this.Invalidate();
  125. }
  126. }
  127. }
  128. }