#if NETFX || NETCORE using System; using System.Drawing; using System.Windows.Forms; using System.ComponentModel; namespace Apewer.Surface { /// public class BlockTable : DataGridView { /// public BlockTable() { SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true); UpdateStyles(); this.Font = FormsUtility.DefaultFont; this.ColumnHeadersHeight = 32; this.RowHeadersVisible = false; this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; this.MultiSelect = false; this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; this.BackgroundColor = FormsUtility.White; this.GridColor = FormsUtility.GraceBorder; this.BorderStyle = BorderStyle.None; this.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal; this.EnableHeadersVisualStyles = false; this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; this.AdvancedColumnHeadersBorderStyle.Left = DataGridViewAdvancedCellBorderStyle.None; this.AdvancedColumnHeadersBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.None; this.AdvancedColumnHeadersBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None; this.AdvancedColumnHeadersBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.Single; this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; this.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; this.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; this.ReadOnly = true; this.AllowUserToAddRows = false; this.AllowUserToDeleteRows = false; this.AllowUserToOrderColumns = false; this.AllowUserToResizeColumns = true; this.AllowUserToResizeRows = false; this.RowsDefaultCellStyle.BackColor = Color.White; // this.RowsDefaultCellStyle.DataSourceNullValue ; this.RowsDefaultCellStyle.SelectionBackColor = FormsUtility.GraceWall; this.RowsDefaultCellStyle.SelectionForeColor = FormsUtility.Black; this.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.False; } /// public void DisableSort() { for (int i = 0; i < this.Columns.Count; i++) { this.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic; } } /// public void EnableSort() { for (int i = 0; i < this.Columns.Count; i++) { this.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic; } } /// public void Beautify() { this.ColumnHeadersHeight = 30; for (int i = 0; i < this.Columns.Count; i++) { this.Columns[i].HeaderCell.Style.BackColor = FormsUtility.GraceBorder; //this.Columns[i].HeaderCell.Style.WrapMode = DataGridViewTriState.False; } for (int i = 0; i < this.Rows.Count; i++) { this.Rows[i].Height = 30; } } /// public void Beautify(int rowIndex) { this.ColumnHeadersHeight = 30; if (rowIndex >= 0) { if (rowIndex < this.Rows.Count) { this.Rows[rowIndex].Height = 30; } } } /// 设置指定单元格的文本颜色。 /// 行。 /// 列。 /// 文本颜色。 public void SetCellColor(int row, string column, Color color) { try { Rows[row].Cells[column].Style.ForeColor = color; Rows[row].Cells[column].Style.SelectionForeColor = color; } catch { } } /// 设置指定单元格的文本颜色为红色。 public void SetCellRed(int row, string column) => SetCellColor(row, column, FormsUtility.Red); /// 设置指定单元格的文本颜色为绿色。 public void SetCellGreen(int row, string column) => SetCellColor(row, column, FormsUtility.Green); /// 设置指定单元格的文本颜色为蓝色。 public void SetCellBlue(int row, string column) => SetCellColor(row, column, FormsUtility.Blue); /// 设置指定单元格的文本颜色为黑色。 public void SetCellBlack(int row, string column) => SetCellColor(row, column, Color.Black); } } #endif