#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 argRowIndex) { this.ColumnHeadersHeight = 30; if (argRowIndex >= 0) { if (argRowIndex < this.Rows.Count) { this.Rows[argRowIndex].Height = 30; } } } /// 设置指定单元格的文本颜色。 /// 行。 /// 列。 /// 文本颜色。 public void SetCellColor(int argRow, string argColumn, Color argColor) { try { Rows[argRow].Cells[argColumn].Style.ForeColor = argColor; Rows[argRow].Cells[argColumn].Style.SelectionForeColor = argColor; } catch { } } /// 设置指定单元格的文本颜色为红色。 /// 行。 /// 列。 public void SetCellRed(int argRow, string argColumn) { SetCellColor(argRow, argColumn, FormsUtility.Red); } /// 设置指定单元格的文本颜色为绿色。 /// 行。 /// 列。 public void SetCellGreen(int argRow, string argColumn) { SetCellColor(argRow, argColumn, FormsUtility.Green); } /// 设置指定单元格的文本颜色为蓝色。 /// 行。 /// 列。 public void SetCellBlue(int argRow, string argColumn) { SetCellColor(argRow, argColumn, FormsUtility.Blue); } /// 设置指定单元格的文本颜色为黑色。 /// 行。 /// 列。 public void SetCellBlack(int argRow, string argColumn) { SetCellColor(argRow, argColumn, Color.Black); } } } #endif