TreeView 复选框图像截断

TreeNode 控件中的 TreeView 允许用户自定义 DrawMode 并添加复选框。 但是,由于 TreeNode 文本绘图的位置,复选框图像将被截断。 为了避免影响正常、常用的使用,可以使用 AppContext 开关设置来避免复选框在这些特定情况下被截断。

满足以下所有条件时,复选框图像将被截断:

  • CheckBoxes 设置为 true
  • DrawMode 设置为 OwnerDrawText
  • DrawDefault 事件中将 true 设置为 OnDrawNode

以前的行为

在以前的版本中,当 TreeView 控件的 CheckBoxes 设置为 trueDrawMode 设置为 OwnerDrawText,并且在 DrawDefault 事件中 true 设置为 OnDrawNode 时,树节点的复选框图像在右边框处被截断。

新行为

通过在项目的运行时配置文件中设置开关 "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true,当 TreeView 在 CheckBoxes 事件中 true 被设置为 DrawModeOwnerDrawText 被设置为 DrawDefaulttrue 被设置为 OnDrawNode 时,树节点复选框将完全显示。

引入的版本

.NET 10

破坏性变更的类型

此更改为行为更改

更改原因

此更改可确保可以完全显示 TreeView 控件中节点的复选框。

手动将 "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true 添加到项目的 runtimeconfig.json 文件中以启用开关。

{
    "runtimeOptions": {
        "configProperties": {
            "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true
        }
    }
}

受影响的 API