我有以下代码:继承文本框丢失caretIndex属性
public class myTextBox : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
if (Char.IsDigit(e.KeyChar)) // Digits are OK
{
// execpt if cursor is at right end
if (this.CaretIndex == this.Text.Length)
{
e.Handled = true; // throw away keypress
}
}
}
}
,我得到的错误:
“MyTextBoxes.myTextBox”不包含“CaretIndex”,没有扩展方法“的定义。 CaretIndex” ......
即使CaretIndex是一个TextBox属性:http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.caretindex(v=vs.110).aspx
哎呀 - 错过了这个问题,现在(希望这是在文档中更加突出。)如何确定光标是否位于文本的右端...(最好不使用ElementHost) –