📄 datagridtextboxcolumn.cs
字号:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace GzglClient.ColumnStyles
{
public class DataGridTextBoxColumn : System.Windows.Forms.DataGridTextBoxColumn
{
private bool m_IsRedIfOverDue = false;
public DataGridTextBoxColumn(string format, string headerText, string mappingName, int width)
{
base.Format = format;
base.HeaderText = headerText;
base.MappingName = mappingName;
base.Width = width;
}
public DataGridTextBoxColumn(string format, string headerText, string mappingName,
int width, bool isRedIfOverDue)
{
base.Format = format;
base.HeaderText = headerText;
base.MappingName = mappingName;
base.Width = width;
m_IsRedIfOverDue = isRedIfOverDue;
}
protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum,
System.Drawing.Rectangle bounds, bool isReadOnly, string instantText, bool cellIsVisible)
{
// Do Nothing
// This is a ReadOnly DataGrid
}
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds,
System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush,
System.Drawing.Brush foreBrush, bool alignToRight)
{
object bVal = GetColumnValueAtRow(source, rowNum);
if (this.Format == "d")
{
try
{
// globalize for german
if (Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName == "de")
bVal = String.Format("{0:d}", Convert.ToDateTime(bVal).ToString("dd/MM/yy"));
else
bVal = String.Format("{0:d}", Convert.ToDateTime(bVal));
}
catch
{
// ignore an invalid cast
}
}
// if the current row is this row, draw the selection back color
if (this.DataGridTableStyle.DataGrid.CurrentRowIndex == rowNum)
{
g.FillRectangle(new SolidBrush(this.DataGridTableStyle.SelectionBackColor), bounds);
g.DrawString(Convert.ToString(bVal), this.DataGridTableStyle.DataGrid.Font,
new SolidBrush(this.DataGridTableStyle.SelectionForeColor), bounds.X + 2, bounds.Y + 2);
}
else
{
g.FillRectangle(backBrush, bounds);
if (m_IsRedIfOverDue)
{
try
{
if (Convert.ToDateTime(bVal).Date < DateTime.Now.Date)
g.DrawString(Convert.ToString(bVal), this.DataGridTableStyle.DataGrid.Font,
new SolidBrush(Color.Red), bounds.X + 2, bounds.Y + 2);
else
g.DrawString(Convert.ToString(bVal), this.DataGridTableStyle.DataGrid.Font, foreBrush,
bounds.X + 2, bounds.Y + 2);
}
catch
{
g.DrawString(Convert.ToString(bVal), this.DataGridTableStyle.DataGrid.Font, foreBrush,
bounds.X + 2, bounds.Y + 2);
}
}
else
{
g.DrawString(Convert.ToString(bVal), this.DataGridTableStyle.DataGrid.Font, foreBrush,
bounds.X + 2, bounds.Y + 2);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -