Private KeyPressSender As Object = Me 转成C# 提示有错误 请高手指点
Private KeyPressSender As Object = Me
private object KeyPressSender = this;
"this" 关键字在上下 文中不可用
这代码 我是在自定义控件中 用的
private object KeyPressSender = this;
private void MyTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (object.ReferenceEquals(KeyPressSender, this))
{
txt.Text = e.KeyChar.ToString();
txt.SelectionStart = txt.Text.Length;
}
}
请高手 多多指点
------解决方案--------------------private object KeyPressSender = this; 去掉
if (object.ReferenceEquals(sender, this))
{
txt.Text = e.KeyChar.ToString();
txt.SelectionStart = txt.Text.Length;
}