Rediger

Del via


TreeView checkbox image truncation

The TreeNode in the TreeView control allows users to customize the DrawMode and add checkboxes. However, the checkbox image will be truncated due to the position of the TreeNode text drawing. To avoid affecting normal, common use, you can use an AppContext switch setting to avoid checkbox truncation in these specific situations.

The checkbox image is truncated when all of the following conditions are met:

  • CheckBoxes is set to true
  • DrawMode is set to OwnerDrawText
  • DrawDefault is set to true in the OnDrawNode event

Previous behavior

In previous versions, when the TreeView control had CheckBoxes set to true, DrawMode set to OwnerDrawText, and DrawDefault set to true in the OnDrawNode event, the TreeNode checkbox images were shown truncated on the right border.

New behavior

By setting the switch "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true in the project's runtime config file, the TreeNode checkboxes are displayed completely when the TreeView has CheckBoxes set to true, DrawMode set to OwnerDrawText, and DrawDefault set to true in the OnDrawNode event.

Version introduced

.NET 10 Preview 1

Type of breaking change

This change is a behavioral change.

Reason for change

This change ensures that the checkbox of the node in the TreeView control can be fully displayed.

Manually add "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true to the project's runtimeconfig.json file to enable the switch.

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

Affected APIs