public partial class Form1 : Form
{
TextBox textBox;
public Form1()
{
InitializeComponent();
textBox = new TextBox() { Height = 30, Width = 200, Text = "Syncfusion Software", Font = new Font("Arial", 11) };
textBox.MouseMove += textBox_MouseMove;
this.Controls.Add(textBox);
}
void textBox_MouseMove(object sender, MouseEventArgs e)
{
var selectionStart = textBox.GetCharIndexFromPosition(e.Location);
textBox.SelectionStart = selectionStart;
textBox.SelectionLength = 0;
}
}这是我的代码,这是一个简单的示例,我试图获得关于TextBox的GetCharIndexFromPosition()方法的清晰信息。
在鼠标移动中,我使用文本框的当前鼠标位置获取字符索引位置,并根据它设置文本框的选择开始。因此,如果我移动鼠标,则将根据鼠标移动来设置选择开始位置或插入符号位置。但当鼠标在文本末尾移动时,选择开始没有设置为最后,这是一个问题。它定格在最后但在此之前。
例如,如果文本框包含文本"stack",则如果鼠标位置在"k“之后,则插入符号位置应该在末尾,但它显示在"c”和"k“之间。GetCharIndexPosition()不能正确返回最后一个字符的值。让我知道这个问题的解决方案
提前谢谢。
致以敬意,
Venkatesan R
https://stackoverflow.com/questions/35177667
复制相似问题