I am doing an usercontrol. It uses Graphics.DrawString to draw Cell's text. On the edit mode, there's a TextBox (Single Line, BorderStyle = None) appearing. How to position the textbox to align the Text?
I am trying to put offset X/Y, but with different Font or FontStyle or Font Size, the TextBox can't handle all situations.
If I uses TextRender.DrawText to draw the Cell's text, the TextBox can align for most of case, much improved from Graphics.DrawString.
After few days' try, I found TextBox uses DrawTextExW, TextRender.DrawText may do so.
For Graphics.DrawString, the left padding and top padding of drawing String is unmeasurable for me, I need to help to get the accurate padding so that I can position TextBox.
OK.
Almost resolved by using StringFormat.SetMeasurableCharacterRanges and graphics.MeasureCharacterRanges to calculate the padding then compensate. Test OK for most of case (Fonts).