MemberManagement/UserControls/DataGridViewDetailButtonColumn.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MemberManagement.UserControls
{
/// <summary>
/// 对象名称:DataGridView操作按钮列(查看详细)
/// 对象说明:通过本类可以实现,在DataGridView控件中,显示一个名为“查看详细”图片按钮的列。
/// 作者姓名:BudStudio 子水良(QQ:1541532664)
/// 编写日期:2010/06/20 04:50:39
/// </summary>
public class DataGridViewDetailButtonColumn : DataGridViewColumn
{
public DataGridViewDetailButtonColumn()
{
this.CellTemplate = new DataGridViewDetailButtonCell();
this.HeaderText = "操作";
}
}
/// <summary>
/// DataGridView操作按钮单元格,继承自DataGridViewButtonCell类。使用本自定义列或单元格前,请
/// 确保应用程序的Properties.Resources资源文件中,包含了分别名为:BtnView、BtnView02的图片。
/// </summary>
public class DataGridViewDetailButtonCell : DataGridViewButtonCell
{
private bool mouseOnDetailButton = false; // 鼠标是否移动到查看详细按钮上
private static Image ImageDetail = Properties.Resources.BtnView; // 查看详细按钮背景图片
private static Pen penDetail = new Pen(Color.FromArgb(135, 163, 193)); // 查看详细按钮边框颜色
private static int nowColIndex = 0; // 当前列序号
private static int nowRowIndex = 0; // 当前行序号
/// <summary>
/// 对单元格的重绘事件进行的方法重写。
/// </summary>
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
cellBounds = PrivatePaint(graphics, cellBounds, rowIndex, cellStyle, true);
base.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
nowColIndex = this.DataGridView.Columns.Count - 1;
}
/// <summary>
/// 私有的单元格重绘方法,根据鼠标是否移动到按钮上,对按钮的不同背景和边框进行绘制。
/// </summary>
private Rectangle PrivatePaint(Graphics graphics, Rectangle cellBounds, int rowIndex, DataGridViewCellStyle cellStyle, bool clearBackground)
{
if (mouseOnDetailButton) // 鼠标移动到查看详细按钮上,更换背景及边框颜色
{
ImageDetail = Properties.Resources.BtnView02;
penDetail = new Pen(Color.FromArgb(162, 144, 77));
}
后面还有 113 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
