简体   繁体   English

C#在文本框中获取焦点位置/索引

[英]C# Get Focused Position / Index In Textbox

How Can I Get Focused Cursor Index To Make Left Key Suppress Examples : 如何获得焦点光标索引以使左键抑制示例:

if (e.KeyCode == Keys.Left && textBox1.Text.FocusIndex == textBox1.text.IndexOf(">")+1)
{
    e.SuppressKeyPress = true;
}

If Focus Cursor Reach The Next Character Of " > " Disable The Left Arrow ... How Can I Get Focused Index or Position ? 如果焦点光标到达“ > ”的下一个字符,请禁用向左箭头...如何获取焦点索引或位置? Thanks, 谢谢,

If for "Focused Cursor Index" you mean Caret position you can use the property SelectionStart of your TextBox. 如果对于“焦点光标索引”是指插入位置,则可以使用文本框的SelectionStart属性。 Like : 喜欢 :

if (e.KeyCode == Keys.Left == textBox1.SelectionStart == textBox1.Text.IndexOf(">"))
{
    e.SuppressKeyPress = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM