How do I convert X y position within a TextBox to a text index?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using a DragEventArgs for a Drop Event and have the x, y Drop Insert position within a TextBox. How do you convert the x, y to and Index within the TextField? I is extremely import for me to find out this inormation! Thank you very much! 回答1: You need to use the GetCharacterIndexFromPoint method of the TextBox : void textBox1_Drop(object sender, DragEventArgs e) { TextBox textBox = (TextBox)sender; Point position = e.GetPosition(textBox); int index = textBox.GetCharacterIndexFromPoint(position, true); string text = (string)e.Data.GetData