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.

153 lines
5.6 KiB

  1. #if NETFX || NETCORE
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.ComponentModel;
  6. namespace Apewer.Surface
  7. {
  8. /// <summary></summary>
  9. public class BlockTable : DataGridView
  10. {
  11. /// <summary></summary>
  12. public BlockTable()
  13. {
  14. SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true);
  15. UpdateStyles();
  16. this.Font = FormsUtility.DefaultFont;
  17. this.ColumnHeadersHeight = 32;
  18. this.RowHeadersVisible = false;
  19. this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  20. this.MultiSelect = false;
  21. this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  22. this.BackgroundColor = FormsUtility.White;
  23. this.GridColor = FormsUtility.GraceBorder;
  24. this.BorderStyle = BorderStyle.None;
  25. this.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal;
  26. this.EnableHeadersVisualStyles = false;
  27. this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
  28. this.AdvancedColumnHeadersBorderStyle.Left = DataGridViewAdvancedCellBorderStyle.None;
  29. this.AdvancedColumnHeadersBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.None;
  30. this.AdvancedColumnHeadersBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None;
  31. this.AdvancedColumnHeadersBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.Single;
  32. this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  33. this.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
  34. this.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
  35. this.ReadOnly = true;
  36. this.AllowUserToAddRows = false;
  37. this.AllowUserToDeleteRows = false;
  38. this.AllowUserToOrderColumns = false;
  39. this.AllowUserToResizeColumns = true;
  40. this.AllowUserToResizeRows = false;
  41. this.RowsDefaultCellStyle.BackColor = Color.White;
  42. // this.RowsDefaultCellStyle.DataSourceNullValue ;
  43. this.RowsDefaultCellStyle.SelectionBackColor = FormsUtility.GraceWall;
  44. this.RowsDefaultCellStyle.SelectionForeColor = FormsUtility.Black;
  45. this.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.False;
  46. }
  47. /// <summary></summary>
  48. public void DisableSort()
  49. {
  50. for (int i = 0; i < this.Columns.Count; i++)
  51. {
  52. this.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic;
  53. }
  54. }
  55. /// <summary></summary>
  56. public void EnableSort()
  57. {
  58. for (int i = 0; i < this.Columns.Count; i++)
  59. {
  60. this.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
  61. }
  62. }
  63. /// <summary></summary>
  64. public void Beautify()
  65. {
  66. this.ColumnHeadersHeight = 30;
  67. for (int i = 0; i < this.Columns.Count; i++)
  68. {
  69. this.Columns[i].HeaderCell.Style.BackColor = FormsUtility.GraceBorder;
  70. //this.Columns[i].HeaderCell.Style.WrapMode = DataGridViewTriState.False;
  71. }
  72. for (int i = 0; i < this.Rows.Count; i++)
  73. {
  74. this.Rows[i].Height = 30;
  75. }
  76. }
  77. /// <summary></summary>
  78. public void Beautify(int argRowIndex)
  79. {
  80. this.ColumnHeadersHeight = 30;
  81. if (argRowIndex >= 0)
  82. {
  83. if (argRowIndex < this.Rows.Count)
  84. {
  85. this.Rows[argRowIndex].Height = 30;
  86. }
  87. }
  88. }
  89. /// <summary>设置指定单元格的文本颜色。</summary>
  90. /// <param name="argRow">行。</param>
  91. /// <param name="argColumn">列。</param>
  92. /// <param name="argColor">文本颜色。</param>
  93. public void SetCellColor(int argRow, string argColumn, Color argColor)
  94. {
  95. try
  96. {
  97. Rows[argRow].Cells[argColumn].Style.ForeColor = argColor;
  98. Rows[argRow].Cells[argColumn].Style.SelectionForeColor = argColor;
  99. }
  100. catch { }
  101. }
  102. /// <summary>设置指定单元格的文本颜色为红色。</summary>
  103. /// <param name="argRow">行。</param>
  104. /// <param name="argColumn">列。</param>
  105. public void SetCellRed(int argRow, string argColumn)
  106. {
  107. SetCellColor(argRow, argColumn, FormsUtility.Red);
  108. }
  109. /// <summary>设置指定单元格的文本颜色为绿色。</summary>
  110. /// <param name="argRow">行。</param>
  111. /// <param name="argColumn">列。</param>
  112. public void SetCellGreen(int argRow, string argColumn)
  113. {
  114. SetCellColor(argRow, argColumn, FormsUtility.Green);
  115. }
  116. /// <summary>设置指定单元格的文本颜色为蓝色。</summary>
  117. /// <param name="argRow">行。</param>
  118. /// <param name="argColumn">列。</param>
  119. public void SetCellBlue(int argRow, string argColumn)
  120. {
  121. SetCellColor(argRow, argColumn, FormsUtility.Blue);
  122. }
  123. /// <summary>设置指定单元格的文本颜色为黑色。</summary>
  124. /// <param name="argRow">行。</param>
  125. /// <param name="argColumn">列。</param>
  126. public void SetCellBlack(int argRow, string argColumn)
  127. {
  128. SetCellColor(argRow, argColumn, Color.Black);
  129. }
  130. }
  131. }
  132. #endif