TreeNode 控制項中的 TreeView 可讓使用者自定義 DrawMode 並新增複選框。 不過,複選框影像將會因為 TreeNode 文字繪圖的位置而遭到截斷。 若要避免影響正常、常見的使用,您可以使用 AppContext 切換設定以免在這些特定情況下截斷複選框的顯示。
符合下列所有條件時,複選框影像會截斷:
-
CheckBoxes設定為true -
DrawMode設定為OwnerDrawText - 在
DrawDefault事件中,true被設定為OnDrawNode
先前的行為
在舊版中,當 TreeView 控件的 CheckBoxes 設定為 true、DrawMode 設定為 OwnerDrawText,並且在 DrawDefault 事件中 true 設定為 OnDrawNode 時,TreeNode 複選框影像在右邊緣會顯示為截斷。
新行為
藉由在專案的運行時間組態檔中設定參數 "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true,當 TreeView CheckBoxes 設定為 true、DrawMode 設定為 OwnerDrawText,且 DrawDefault 設定為 true 事件中的 OnDrawNode 時,就會完全顯示 TreeNode 複選框。
引進的版本
.NET 10
中斷性變更的類型
這項變更是 行為改變。
變更的原因
這項變更可確保 TreeView 控制件中的節點複選框可以完全顯示。
建議的動作
手動將 "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true 新增至專案的 runtimeconfig.json 檔案,以啟用開關。
{
"runtimeOptions": {
"configProperties": {
"System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true
}
}
}