Skip to content

Commit 8ecf0b8

Browse files
committed
Add the calculation of the control border when calculating the TreeNode inversion coordinates and scroll bar status
1 parent 3841b91 commit 8ecf0b8

File tree

1 file changed

+9
-3
lines changed
  • src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView

1 file changed

+9
-3
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Controls/TreeView/TreeView.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -2847,12 +2847,18 @@ private unsafe void CustomDraw(ref Message m)
28472847

28482848
if (RightToLeft == RightToLeft.Yes && RightToLeftLayout)
28492849
{
2850+
int borderWidth = BorderStyle switch
2851+
{
2852+
BorderStyle.FixedSingle => 1,
2853+
BorderStyle.Fixed3D => 2,
2854+
_ => 0
2855+
};
2856+
28502857
// Reverse the X-axis drawing coordinates of the rectangle.
2851-
// Offset the text four pixels to the left to ensure that the text is centered on the fill rectangle.
2852-
int invertedX = Width - bounds.X - textSize.Width - 4;
2858+
int invertedX = Width - bounds.X - textSize.Width - borderWidth * 2;
28532859

28542860
// Subtract the scroll bar width when the scroll bar appears.
2855-
if (Height <= PreferredHeight)
2861+
if (Height - borderWidth * 2 < PreferredHeight)
28562862
{
28572863
float dpiScale = (float)DeviceDpi / (float)ScaleHelper.InitialSystemDpi;
28582864
invertedX -= (int)(SystemInformation.VerticalScrollBarWidth * Math.Round(dpiScale, 2));

0 commit comments

Comments
 (0)