gpt4 book ai didi

c# - DataGridView 的 RowPrePaint 中的 PaintParts 不起作用?

转载 作者:太空宇宙 更新时间:2023-11-03 13:41:41 24 4
gpt4 key购买 nike

我认为 PaintParts 指示默认应绘制哪些部分。 It seems to work OK but when the DataGridViewCell is selected, everything is painted by default.我只想绘制除内容以外的所有内容,这是我的代码:

private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e){
e.PaintParts = DataGridViewPaintParts.All & ~DataGridViewPaintParts.ContentForeground;
}

当单元格未被选中时它工作正常,但是如果我选择一个单元格,它会默认绘制所有背景和内容。默认/标准 DataGridView 工作正常,但我正在处理自定义/第三方 DataGridView

你能给我解释一下那是什么并给我一些解决方案吗?

非常感谢!

最佳答案

我相信您可以指定以这种方式绘制除内容前景之外的所有内容。

我已经这样做了,而且很有效。

这应该正是您所需要的,除非您只需要特定的单元格而不需要绘制所有的 paintParts。

private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
e.PaintCells(e.ClipBounds, DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.Border | DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground);
e.Handled = true;

//The e.Handled = true tells the event handler that the event has been completed and that the system doesn't need to do anymore processing. This line is required to ensure it doesn't process any further(paint more stuff).
}

附言。刚找到这个

C# DataGridViewCheckBoxColumn Hide/Gray-Out

关于c# - DataGridView 的 RowPrePaint 中的 PaintParts 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16785328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com