我正在尝试获得这样的效果:当我单击文本框时,插入符号移动到索引0示例"hello“(|hello)现在当我写东西时,我希望文本出现在"hello”之前示例"hello2hello“
我已经使用了如下函数:
.Select(0,0);
.CurrentIndex=0;
.SelectionStart=0 SelectionLenght=0;这些函数仅在events、KeyDown或TextChanged事件中有效。不幸的是,这些操作并没有产生想要的效果,我得到的是我输入的镜像。示例(而不是hello,我得到olleh)如何在文本框内单击后更改插入符号的索引?
发布于 2012-03-20 19:52:25
尝尝这个
public string TBName = "";
private void txtResult_KeyPress(object sender, KeyPressEventArgs e)
{
if (TBName != ((TextBox)sender).Name)
{
((TextBox)sender).SelectionStart = 0;
((TextBox)sender).SelectionLength = 0;
TBName = ((TextBox)sender).Name;
}
}您还可以将其链接到多个TextBoxes
https://stackoverflow.com/questions/9785630
复制相似问题