问题描述
我最近将一个项目从 .NET 4
迁移到 .NET 4.7.2
,这在 WinForms DataGridView 标题中引入了更改.
I recently migrated a Project from .NET 4
to .NET 4.7.2
which introduced a change in the WinForms DataGridView Headers.
预迁移如下所示:
如您所见,我当前单击的单元格的标题未选中.迁移后相同的 DataGridView 如下所示:我在 发行说明
As you can see, the Header of the cell i currently clicked is not selected. After the Migration the same DataGridView looks like this: I could not find any Information mentioning changes in the WinForms DataGridView at the Release Notes
我尝试使用此处的以下代码设置颜色如何更改winform DataGridview header的颜色?
I tried to set the Color using the following code from here how to change the color of winform DataGridview header?
this.dgvUserFields.ColumnHeadersDefaultCellStyle.BackColor = System.Drawing.SystemColors.ControlDark;
this.dgvUserFields.EnableHeadersVisualStyles = false;
但代码似乎没有改变任何东西.
But the code does not seem to change anything.
是否有一些资源确认了重大更改,以及如何修复它?
Are the some resources confirming that breaking change, and how to fix it ?
推荐答案
行为记录在 .NET Framework 4.7.2 中的新增功能 在 DataGridView 改进 部分:
The behavior is documented in What's new in accessibility in the .NET Framework 4.7.2 in DataGridView improvements section:
当 System.Windows.Forms.DataGridView.SelectionMode
设置为System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
,列标题将更改颜色以将当前列指示为用户在当前行中的单元格之间切换.
When the
System.Windows.Forms.DataGridView.SelectionMode
is set toSystem.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
, the column header will change color to indicate the current column as the user tabs through the cells in the current row.
在 .NET Framework 4.7.2 中,渲染 DataGridViewColumnHeaderCell
时,它会检查列 IsHighlighted
,然后将列渲染为推送状态,这里是要检测的逻辑IsHighlighted
:
In .NET Framework 4.7.2 when rendering DataGridViewColumnHeaderCell
, it checks if the column IsHighlighted
, then it renders the column in pushed state and here is the logic to detect IsHighlighted
:
private bool IsHighlighted()
{
return this.DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect &&
this.DataGridView.CurrentCell != null && this.DataGridView.CurrentCell.Selected &&
this.DataGridView.CurrentCell.OwningColumn == this.OwningColumn &&
AccessibilityImprovements.Level2;
}
正如你在上面的代码中看到的,有 &&AccessibilityImprovements.Level2
.这意味着如果您关闭该功能,行为将被重置.
As you can see in above code, there is && AccessibilityImprovements.Level2
. It means if you turn the feature off, the behavior will be reset.
正如 Taw,您可以关闭该功能.为此,您可以将此设置块添加到 app.config
文件中:
As also mentioned in the comments by Taw, you can turn the feature off. To do so, you can add this block of setting to app.config
file:
<runtime>
<AppContextSwitchOverrides value="Switch.UseLegacyAccessibilityFeatures=false;Switch.UseLegacyAccessibilityFeatures.2=true" />
</runtime>
这篇关于.Net 4.0 和 .NET 4.7.2 标头选择之间 DataGridView 的重大变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论