-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recalculate the node position of the TreeView when DrawMode = TreeViewDrawMode.OwnerDrawText #12698
base: main
Are you sure you want to change the base?
Recalculate the node position of the TreeView when DrawMode = TreeViewDrawMode.OwnerDrawText #12698
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12698 +/- ##
====================================================
- Coverage 76.13468% 61.29163% -14.84306%
====================================================
Files 3242 1541 -1701
Lines 642363 158281 -484082
Branches 47271 14743 -32528
====================================================
- Hits 489061 97013 -392048
+ Misses 149751 60571 -89180
+ Partials 3551 697 -2854
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had you tested this change at different scaling factors and in different level nodes in a tree view? For example 3rd level child?
It will be helpful to add code comments that describe what the constants are for.
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs:2907
- [nitpick] The method name 'PreferredHeight' is not very descriptive. Consider renaming it to 'CalculatePreferredHeight'.
private int PreferredHeight
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs:2921
- [nitpick] The method name 'GetNodeHeight' is not very descriptive. Consider renaming it to 'CalculateNodeHeight'.
private int GetNodeHeight(TreeNode node)
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs:2741
- Using 'goto' is generally considered bad practice. Consider refactoring the code to eliminate the need for 'goto'.
goto default;
8ecf0b8
to
c5f0f04
Compare
No regressions found in private PRs |
@LeafShi1 - even though "issue5" as reported by Olina, is not a regression from the previous release, it is a regression from .NET Framework, could you please investigate it? |
ac643af
to
b4fc154
Compare
402e5a3
to
b4fc154
Compare
d7b8138
to
d1bbb32
Compare
Rebase main
…ithub.com/LeafShi1/winforms into Issue_12681_fix_recalculate_node_position
{ | ||
float dpiScale = (float)DeviceDpi / ScaleHelper.OneHundredPercentLogicalDpi; | ||
|
||
PInvoke.SetWindowPos((HWND)editHandle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #12681
Root Cause
When
treeView.DrawMode = TreeViewDrawMode.OwnerDrawText
, the node'sFillRectangle
andFocusRectangle
positions are calculated incorrectlyProposed changes
CustomDraw
of the TreeView.cs, WhenRightToLeft == RightToLeft.Yes && RightToLeftLayout
reverses the X drawing coordinates ofFillRectangle
andFocusRectangle
Customer Impact
Regression?
Risk
Screenshots
Before
After
When setting RightToLeft = Yes, RightToLeftLayout = True and .DrawMode = TreeViewDrawMode.OwnerDrawText, the selected node box is fully rendered

Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow