📄 datagridprioritycolumn.cs
字号:
using System;
using System.Collections;
using System.IO;
using System.Windows.Forms;
using System.Resources;
using System.Drawing;
namespace GzglClient.ColumnStyles
{
public class DataGridPriorityColumn : System.Windows.Forms.DataGridTextBoxColumn
{
private Hashtable m_HtImages = new Hashtable();
private const string c_PriorityImagesPath = @"Images\";
private ResourceManager m_ResourceManager =
new ResourceManager("TaskVision.Localize", System.Reflection.Assembly.GetExecutingAssembly());
public DataGridPriorityColumn(string headerText, string mappingName, int width)
{
base.HeaderText = headerText;
base.MappingName = mappingName;
base.Width = width;
}
protected override void Edit(System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Rectangle bounds, bool isReadOnly,
string instantText, bool cellIsVisible)
{
// do nothing
}
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);
Image imageToDraw=null;
// we're caching the image in a hashtable
if (m_HtImages.ContainsKey(bVal))
imageToDraw = (Image) m_HtImages[bVal];
else
{
// get the image from disk and cache it
try
{
imageToDraw = Image.FromFile(c_PriorityImagesPath + (string) bVal + ".gif");
m_HtImages.Add(bVal, imageToDraw);
}
catch
{
MessageBox.Show("图像:" + " " +
Application.StartupPath + @"\" + c_PriorityImagesPath +
(string) bVal +
"未找到!", "文件无法找到");
/*LogError.Write(m_ResourceManager.GetString("The_image_file") + " " +
Application.StartupPath + @"\" + c_PriorityImagesPath +
(string) bVal + m_ResourceManager.GetString("gif_was_not_found"));
return; // Necessary in C# -- otherwise it won't compile
// because imageToDraw is used below and might not be assigned.*/
}
}
// 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);
else
g.FillRectangle(backBrush, bounds);
g.DrawImage(imageToDraw, new Point(bounds.X, bounds.Y));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -