CustomGridView.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Data;
  7. using System.Windows.Forms;
  8. using System.Threading;
  9. using Core.LZMes.Client.UIM.comm;
  10. namespace Core.LZMes.Client.UIM.comm
  11. {
  12. class CustomGridView : DataGridView
  13. {
  14. public CustomGridView(Scenes gridType,DataSet ds)
  15. {
  16. //this.Name = gridType.ToString();
  17. this.AllowUserToAddRows = false;
  18. this.AllowUserToDeleteRows = false;
  19. this.AllowUserToResizeColumns = false;
  20. this.AllowUserToResizeRows = false;
  21. this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
  22. this.BorderStyle = BorderStyle.FixedSingle;
  23. this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  24. this.ColumnHeadersVisible = false;
  25. this.RowHeadersVisible = false;
  26. this.Width = 200;
  27. this.CellBorderStyle = DataGridViewCellBorderStyle.Single;
  28. this.ReadOnly = true;
  29. this.RowsDefaultCellStyle.SelectionBackColor = Color.LightSteelBlue;
  30. this.RowsDefaultCellStyle.SelectionForeColor = Color.FromArgb(61, 0, 221);
  31. this.RowsDefaultCellStyle.BackColor = Color.LightSteelBlue;
  32. this.BorderStyle = BorderStyle.None;
  33. this.BackgroundColor = Color.LightSteelBlue;
  34. this.ScrollBars = ScrollBars.None;
  35. this.RowTemplate.Height = 15;
  36. this.FontHeight = 10;
  37. this.Font = new Font("宋体", 9);
  38. switch (gridType.ToString())
  39. {
  40. case "PLTCM":
  41. this.DataSource = ds.Tables["pltcm"];
  42. this.Left = 50;
  43. this.Top = 0;
  44. break;
  45. case "CAL":
  46. this.DataSource = ds.Tables["cal"];
  47. this.Left = 570;
  48. this.Top = 320;
  49. break;
  50. case "RCL":
  51. this.DataSource = ds.Tables["rcl"];
  52. this.Left = 710;
  53. this.Top = 150;
  54. break;
  55. }
  56. this.Paint += new PaintEventHandler(myGridView_Paint);
  57. }
  58. /// <summary>
  59. /// 重绘
  60. /// </summary>
  61. /// <param name="sender"></param>
  62. /// <param name="e"></param>
  63. void myGridView_Paint(object sender, PaintEventArgs e)
  64. {
  65. int width = 0;
  66. int height = 0;
  67. foreach (DataGridViewColumn cc in this.Columns)
  68. {
  69. width = width + cc.Width;
  70. }
  71. foreach (DataGridViewRow r in this.Rows)
  72. {
  73. bool hasvalue = false;
  74. int cs = this.Columns.Count;
  75. for (int i = 0; i < cs; i++)
  76. {
  77. if (Convert.ToString(r.Cells[i].Value) != "")
  78. {
  79. hasvalue = true;
  80. }
  81. }
  82. if (!hasvalue)
  83. {
  84. r.Height = 0;
  85. }
  86. height = height + r.Height;
  87. }
  88. this.Width = width + 1;
  89. this.Height = height + 1;
  90. }
  91. Int32 flicktime = 0;
  92. /// <summary>
  93. /// 闪烁
  94. /// </summary>
  95. /// <param name="i"></param>
  96. public void Flicker(Int32 i)
  97. {
  98. flicktime = i;
  99. Thread th = new Thread(DrawRect);
  100. th.Start();
  101. }
  102. bool _StopThread = false;
  103. void DrawRect()
  104. {
  105. try
  106. {
  107. DateTime t1 = DateTime.Now;
  108. bool a = false;
  109. while (!_StopThread)
  110. {
  111. try
  112. {
  113. if (a)
  114. {
  115. Graphics myGraphics = this.CreateGraphics();
  116. Rectangle myRectangle = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
  117. Pen myPen = new Pen(Color.Blue, 3F);
  118. myGraphics.DrawRectangle(myPen, myRectangle);
  119. //myGraphics.Dispose();
  120. //myPen.Dispose();
  121. }
  122. else
  123. {
  124. Graphics myGraphics = this.CreateGraphics();
  125. Rectangle myRectangle = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
  126. Pen myPen = new Pen(Color.Red, 3F);
  127. myGraphics.DrawRectangle(myPen, myRectangle);
  128. //myGraphics.Dispose();
  129. //myPen.Dispose();
  130. }
  131. a = !a;
  132. Thread.Sleep(200);
  133. }
  134. catch { }
  135. DateTime t2 = DateTime.Now;
  136. TimeSpan ts = t2 - t1;
  137. if (ts.TotalSeconds > flicktime)
  138. {
  139. _StopThread = true;
  140. }
  141. }
  142. _StopThread = false;
  143. this.BeginInvoke(new MethodInvoker(this.Refresh));
  144. }
  145. catch { }
  146. }
  147. }
  148. }