C# datagridview.cellpaintting事件刷新问题

wenhu420 wenhu420 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如何手动调用cellpaintting进行刷新呢?下面是一例,对datagridview的单元格进行重绘,因没有办法手动调用cellpaintting事件,所以,无法对单元格强制绘制,我试用invalidate()进行强行重绘,结果也不调用cellpaintting,而是调用onpaint.




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DatagridviewTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Rows.Add(10);
}

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex != -1)
{
e.Graphics.DrawString(e.RowIndex .ToString (), e.CellStyle.Font, new SolidBrush(Color.Red), e.CellBounds);
e.PaintContent(e.CellBounds);
e.Handled = true;
}


}


}
}
...全文
评论 2
收藏 已收藏
分享
返回顶部
wenhu420
C# 111,130 成员 642,539 内容