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.
|
|
#if NETFX || NETCORE
using System; using System.Drawing; using System.Windows.Forms; using System.ComponentModel;
namespace Apewer.Surface {
/// <summary></summary>
public class BlockTable : DataGridView {
/// <summary></summary>
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; }
/// <summary></summary>
public void DisableSort() { for (int i = 0; i < this.Columns.Count; i++) { this.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic; } }
/// <summary></summary>
public void EnableSort() { for (int i = 0; i < this.Columns.Count; i++) { this.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic; } }
/// <summary></summary>
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; } }
/// <summary></summary>
public void Beautify(int argRowIndex) { this.ColumnHeadersHeight = 30; if (argRowIndex >= 0) { if (argRowIndex < this.Rows.Count) { this.Rows[argRowIndex].Height = 30; } } }
/// <summary>设置指定单元格的文本颜色。</summary>
/// <param name="argRow">行。</param>
/// <param name="argColumn">列。</param>
/// <param name="argColor">文本颜色。</param>
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 { } }
/// <summary>设置指定单元格的文本颜色为红色。</summary>
/// <param name="argRow">行。</param>
/// <param name="argColumn">列。</param>
public void SetCellRed(int argRow, string argColumn) { SetCellColor(argRow, argColumn, FormsUtility.Red); }
/// <summary>设置指定单元格的文本颜色为绿色。</summary>
/// <param name="argRow">行。</param>
/// <param name="argColumn">列。</param>
public void SetCellGreen(int argRow, string argColumn) { SetCellColor(argRow, argColumn, FormsUtility.Green); }
/// <summary>设置指定单元格的文本颜色为蓝色。</summary>
/// <param name="argRow">行。</param>
/// <param name="argColumn">列。</param>
public void SetCellBlue(int argRow, string argColumn) { SetCellColor(argRow, argColumn, FormsUtility.Blue); }
/// <summary>设置指定单元格的文本颜色为黑色。</summary>
/// <param name="argRow">行。</param>
/// <param name="argColumn">列。</param>
public void SetCellBlack(int argRow, string argColumn) { SetCellColor(argRow, argColumn, Color.Black); }
} }
#endif
|