DataGridViewCellStyle.ForeColor无法按预期工作 [英] DataGridViewCellStyle.ForeColor not working as expected

查看:76
本文介绍了DataGridViewCellStyle.ForeColor无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WinForms 2.0应用程序,我在当前单元格(IDataGridViewEditingControl)中使用DataGridView和自定义编辑控件。

I'm my WinForms 2.0 application I'm using a DataGridView and a custom edit control within the current cell (IDataGridViewEditingControl).

当前单元格使用我的自定义从文本框继承并实现IDataGridViewEditingControl接口的edit控件。现在,此控件注册到TextChanged事件,以便在编辑值时执行一些验证逻辑,并注册到Leave事件,以将自定义编辑控件中的某些视觉效果应用于DataGridView单元。

The current cell uses my custom edit control that inherits from textbox and implements the IDataGridViewEditingControl interface. This control now registers to the TextChanged event in order to perform some validation logic while the value is edited and to the Leave event to apply some visual effects from the custom edit control to the DataGridView cell.

代码看起来像这样:

public class CustomerTextEditingControl : CustomerTextBox, IDataGridViewEditingControl
{
    ...
    protected override void OnLeave(object sender, EventArgs e)
    {
        dataGridView[_col, _row].Style.BackColor = BackgroundColor;
        dataGridView[_col, _row].Style.ForeColor = ForegroundColor;
        ...
    }
    ...
}

现在这是我的问题:尽管单元格的背景以BackgroundColor可能的任何颜色正确呈现,但无论ForegroundColor是什么颜色,文本本身始终以黑色呈现。首先,我认为可能还有另一种样式适用于单元格的内容,但是我在那里找不到任何东西。所以我现在很困惑:-)

Here's my problem now: While the cell's background is properly rendered in whatever color BackgroundColor might be, the text itself is always rendered in black, no matter what color ForegroundColor is. First I thought there might be another Style that applies to the cell's content, but I couldn't find anything there. So I'm puzzled right now :-)

任何帮助都将不胜感激!

Any help is greatly appreciated!

感谢
Marc

Thanks Marc

推荐答案

发现了问题:DataGridView类被子类化并且OnPaintCell方法被覆盖。唯一考虑的样式属性是BackColor ...

Found the problem: the DataGridView class was subclassed and the OnPaintCell method overridden. The only style attribute that was taken account of was BackColor ...

这篇关于DataGridViewCellStyle.ForeColor无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆