OS: RS4 X64
VS: Dev16 16.2.0 Preview 1.0 [28913.52.d16.2]
.NET Core: 3.0.100-preview6-011867 from Master branch
More Info:
This issue can repro in TextBox control too, but RichTextBox control works well.
Steps to reproduce:
Actual:
Both of the returned values are 0.

Expected:
These two methods should return the correct values, like it works in .NET Framework.

@John-Qiao Can you see if this still repros and tell us if this is a regression from an earlier .NET Core Build?
I think this is caused by a regression introduced in #791 https://github.com/dotnet/winforms/commit/c1a3b671e0ad2d3a19ff5970b42b6a900e78ec8d.
More info: https://github.com/dotnet/winforms/commit/c1a3b671e0ad2d3a19ff5970b42b6a900e78ec8d#r34050026
I suspect we need to perform a thorough review of that change, or revert it back.
@merriemcgaw @RussKie This issue still repros in the latest .NET Core 3.0.100-preview7-012578 version from Master branch. And in my test result, it's a regressions issue from .NET Core 3.0.100-preview5-011534 version.
Yes. It looks like the EM_* messages are incorrect. Bizarely they were incorrect before my change (when defined in RichTextBoxConstants.cs) but it was being used in different places.
https://github.com/dotnet/winforms/pull/791/files#diff-aafd5fb74483abd9f7febf2c487e1385L60

@John-Qiao could you please retest when you have time.
Thank you
Awesome! Thank you
@RussKie could we reopen this issue?
I retest this issue in .NET Core 3.0.100-preview7-012793 from Release branch, but I found this issue is not fixed in the following scenario:
`MaskedTextBox myObj = new MaskedTextBox();
//TextBox myObj = new TextBox();
//RichTextBox myObj = new RichTextBox();
myObj.Text = "eöü****#*$&@&$4ä1452";
Point expect = myObj.GetPositionFromCharIndex(15);
int index = myObj.GetCharIndexFromPosition(new Point(expect.X, expect.Y));`
When run the above codes in .NET Core project, the index variable value is incorrect in debug result, it should returns 15, but the actual value is 19 in debugging. MaskTextBox and TextBox controls both have the same issue. If run the same codes in .NET Framework project, the index variable get the correct value 15 in debugging. Please check the screenshots:
Testing in .NET Core:

Testing in .NET Framework:

More information: If change MaskTextBox/TextBox control's width to a large value in code like below, the index value will be returned correctly in .NET Core project.
`MaskedTextBox myObj = new MaskedTextBox();
//TextBox myObj = new TextBox();
myObj.Size = new System.Drawing.Size(200, 20);
//RichTextBox myObj = new RichTextBox();
myObj.Text = "eöü****#*$&@&$4ä1452";
Point expect = myObj.GetPositionFromCharIndex(15);
int index = myObj.GetCharIndexFromPosition(new Point(expect.X, expect.Y));`
It looks there is something else in play here.
I've added few tests and it looks like when an input is longer than a ~95 pixels it fails:
void Test(string s)
{
Debug.WriteLine($"---- {s}");
for (int i = 10; i < s.Length; i++)
{
Point expect = myObj.GetPositionFromCharIndex(i);
int index = myObj.GetCharIndexFromPosition(new Point(expect.X, expect.Y));
Debug.WriteLine($"symbol: {s[i]}, i: {i}, expect: {expect}, index: {index}");
}
}
Results:
---- 01234567890123456789
symbol: 3, i: 13, expect: {X=79,Y=0}, index: 13
symbol: 4, i: 14, expect: {X=85,Y=0}, index: 14
symbol: 5, i: 15, expect: {X=91,Y=0}, index: 15
symbol: 6, i: 16, expect: {X=97,Y=0}, index: 19
symbol: 7, i: 17, expect: {X=103,Y=0}, index: 19
symbol: 8, i: 18, expect: {X=109,Y=0}, index: 19
symbol: 9, i: 19, expect: {X=115,Y=0}, index: 19
----
---- e4öü****#*$&@&$4ä12452
symbol: @, i: 12, expect: {X=75,Y=0}, index: 12
symbol: &, i: 13, expect: {X=86,Y=0}, index: 13
symbol: $, i: 14, expect: {X=96,Y=0}, index: 21
symbol: 4, i: 15, expect: {X=102,Y=0}, index: 21
symbol: ä, i: 16, expect: {X=108,Y=0}, index: 21
symbol: 1, i: 17, expect: {X=114,Y=0}, index: 21
symbol: 2, i: 18, expect: {X=120,Y=0}, index: 21
symbol: 4, i: 19, expect: {X=126,Y=0}, index: 21
symbol: 5, i: 20, expect: {X=132,Y=0}, index: 21
symbol: 2, i: 21, expect: {X=138,Y=0}, index: 21
----
---- abcdefghijklmnopqrstuvwxyz
symbol: o, i: 14, expect: {X=84,Y=0}, index: 14
symbol: p, i: 15, expect: {X=91,Y=0}, index: 15
symbol: q, i: 16, expect: {X=98,Y=0}, index: 25
symbol: r, i: 17, expect: {X=105,Y=0}, index: 25
symbol: s, i: 18, expect: {X=109,Y=0}, index: 25
symbol: t, i: 19, expect: {X=114,Y=0}, index: 25
symbol: u, i: 20, expect: {X=118,Y=0}, index: 25
symbol: v, i: 21, expect: {X=125,Y=0}, index: 25
symbol: w, i: 22, expect: {X=131,Y=0}, index: 25
symbol: x, i: 23, expect: {X=140,Y=0}, index: 25
symbol: y, i: 24, expect: {X=146,Y=0}, index: 25
symbol: z, i: 25, expect: {X=152,Y=0}, index: 25
----
---- 11111111111111111111
symbol: 1, i: 13, expect: {X=79,Y=0}, index: 13
symbol: 1, i: 14, expect: {X=85,Y=0}, index: 14
symbol: 1, i: 15, expect: {X=91,Y=0}, index: 15
symbol: 1, i: 16, expect: {X=97,Y=0}, index: 19
symbol: 1, i: 17, expect: {X=103,Y=0}, index: 19
symbol: 1, i: 18, expect: {X=109,Y=0}, index: 19
symbol: 1, i: 19, expect: {X=115,Y=0}, index: 19
I've run the same code against NET 4.7.2 and observed the same results with myObj.Font = SystemFonts.MessageBoxFont;:
---- 01234567890123456789
symbol: 3, i: 13, expect: {X=79,Y=0}, index: 13
symbol: 4, i: 14, expect: {X=85,Y=0}, index: 14
symbol: 5, i: 15, expect: {X=91,Y=0}, index: 15
symbol: 6, i: 16, expect: {X=97,Y=0}, index: 19
symbol: 7, i: 17, expect: {X=103,Y=0}, index: 19
symbol: 8, i: 18, expect: {X=109,Y=0}, index: 19
symbol: 9, i: 19, expect: {X=115,Y=0}, index: 19
----
---- e4öü****#*$&@&$4ä12452
symbol: @, i: 12, expect: {X=75,Y=0}, index: 12
symbol: &, i: 13, expect: {X=86,Y=0}, index: 13
symbol: $, i: 14, expect: {X=96,Y=0}, index: 21
symbol: 4, i: 15, expect: {X=102,Y=0}, index: 21
symbol: ä, i: 16, expect: {X=108,Y=0}, index: 21
symbol: 1, i: 17, expect: {X=114,Y=0}, index: 21
symbol: 2, i: 18, expect: {X=120,Y=0}, index: 21
symbol: 4, i: 19, expect: {X=126,Y=0}, index: 21
symbol: 5, i: 20, expect: {X=132,Y=0}, index: 21
symbol: 2, i: 21, expect: {X=138,Y=0}, index: 21
----
---- abcdefghijklmnopqrstuvwxyz
symbol: o, i: 14, expect: {X=84,Y=0}, index: 14
symbol: p, i: 15, expect: {X=91,Y=0}, index: 15
symbol: q, i: 16, expect: {X=98,Y=0}, index: 25
symbol: r, i: 17, expect: {X=105,Y=0}, index: 25
symbol: s, i: 18, expect: {X=109,Y=0}, index: 25
symbol: t, i: 19, expect: {X=114,Y=0}, index: 25
symbol: u, i: 20, expect: {X=118,Y=0}, index: 25
symbol: v, i: 21, expect: {X=125,Y=0}, index: 25
symbol: w, i: 22, expect: {X=131,Y=0}, index: 25
symbol: x, i: 23, expect: {X=140,Y=0}, index: 25
symbol: y, i: 24, expect: {X=146,Y=0}, index: 25
symbol: z, i: 25, expect: {X=152,Y=0}, index: 25
----
---- 11111111111111111111
symbol: 1, i: 13, expect: {X=79,Y=0}, index: 13
symbol: 1, i: 14, expect: {X=85,Y=0}, index: 14
symbol: 1, i: 15, expect: {X=91,Y=0}, index: 15
symbol: 1, i: 16, expect: {X=97,Y=0}, index: 19
symbol: 1, i: 17, expect: {X=103,Y=0}, index: 19
symbol: 1, i: 18, expect: {X=109,Y=0}, index: 19
symbol: 1, i: 19, expect: {X=115,Y=0}, index: 19
----
I have run a number of tests and it looks like the issue affects textbox controls which size (width or height) is less than necessary to show all text when attempting to get a position from a character which is outside of the client area of the control.
The issue reproduces consistently in both .NET Fx and .NET Core (⚠️ one must account for the default font change in .NET Core #656 and set the default font in a .NET Fx app to SystemFonts.MessageBoxFont)
I was puzzled what was special about 94-96 range until I realised that the default size for a TextBox and MaskedTextBox controls was {Width=100, Height=23}, so the issue was observed for all chars that weren't fully rendered (clipped by the right border) or outside of the visible area.

---- TextBox .Size={Width=100, Height=23} .Multiline=False .Text=eöü****#*$&@&$4ä1452
symbol: 4, position: {X=96,Y=0}, i: 14, index: 19 <---- different!
symbol: ä, position: {X=102,Y=0}, i: 15, index: 19 <---- different!
symbol: 1, position: {X=108,Y=0}, i: 16, index: 19 <---- different!
symbol: 4, position: {X=114,Y=0}, i: 17, index: 19 <---- different!
symbol: 5, position: {X=120,Y=0}, i: 18, index: 19 <---- different!
---- TextBox .Size={Width=50, Height=23} .Multiline=False .Text=eöü****#*$&@&$4ä1452
symbol: *, position: {X=48,Y=0}, i: 8, index: 19 <---- different!
symbol: $, position: {X=53,Y=0}, i: 9, index: 19 <---- different!
symbol: &, position: {X=59,Y=0}, i: 10, index: 19 <---- different!
symbol: @, position: {X=69,Y=0}, i: 11, index: 19 <---- different!
symbol: &, position: {X=80,Y=0}, i: 12, index: 19 <---- different!
symbol: $, position: {X=90,Y=0}, i: 13, index: 19 <---- different!
....clip...
---- TextBox .Size={Width=250, Height=23} .Multiline=False .Text=eöü****#*$&@&$4ä1452
I have a demo app that explores a number of use cases - https://github.com/RussKie/Test-GetCharIndexFromPosition
@John-Qiao given that the behaviour is consistent in both .NET Fx and .NET Core I'm closing the issue.