共用方式為


TreeView 複選框影像截斷

TreeView 控制項中的 TreeNode 可讓使用者自定義 DrawMode 並新增複選框。 不過,複選框影像將會因為 TreeNode 文字繪圖的位置而遭到截斷。 若要避免影響正常、常見的使用,您可以使用 AppContext 切換設定以免在這些特定情況下截斷複選框的顯示。

符合下列所有條件時,複選框影像會截斷:

  • CheckBoxes 設定為 true
  • DrawMode 設定為 OwnerDrawText
  • OnDrawNode 事件中,DrawDefault 被設定為 true

先前的行為

在舊版中,當 TreeView 控件的 CheckBoxes 設定為 trueDrawMode 設定為 OwnerDrawText,並且在 OnDrawNode 事件中 DrawDefault 設定為 true 時,TreeNode 複選框影像在右邊緣會顯示為截斷。

新行為

藉由在專案的運行時間組態檔中設定參數 "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true,當 TreeView CheckBoxes 設定為 trueDrawMode 設定為 OwnerDrawText,且 DrawDefault 設定為 OnDrawNode 事件中的 true 時,就會完全顯示 TreeNode 複選框。

引進的版本

.NET 10 Preview 1

中斷性變更的類型

這項變更是 行為改變

變更的原因

這項變更可確保 TreeView 控制件中的節點複選框可以完全顯示。

手動將 "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true 新增至專案的 runtimeconfig.json 檔案,以啟用開關。

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

受影響的 API