您好,问下C#自定义Edit控件输入汉字会出现两遍,是什么问题?
输入数字跟字母就只触发一次KeyPress,输入汉字就会变成触发两次KeyPress,比如输入“中国”就会变成“中国中国”
测试输入法中搜狗输入法跟紫光输入法都会出现这种情况,
使用智能ABC,王码五笔不会。
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (this.ReadOnly) return;
if (!this.Enabled) return;
//base.OnKeyPress (e);
if(e.KeyChar!=Convert.ToChar(Keys.Back))
if (this.EditMode==EditMode.Picker && this.fastkey!=null)
{
if (e.KeyChar==Convert.ToChar(Keys.Enter))
{
//结束编辑
if (this.picker!=null)
{
this.Value=this.picker.Value;
this.picker.cancel=false;
this.picker.Close();
this.picker=null;
this.popuped=false;
}
//更新
}
else
{
this.hold=true;
Onkeypress( e);
if (!this.popuped)
{
this.ShowPopup();
this.picker.OnFastKey(this.fastkey,this.ValueText);
}
else
{
this.picker.OnFastKey(this.fastkey,this.ValueText);
}
this.Focus();
this.hold=false;
}
}
else
{
Onkeypress( e);
//base.OnKeyPress(e);
}
if (e.KeyChar==Convert.ToChar(Keys.Enter))
{
this.NextControlFocus();
return;
}
}
[解决办法]
帮等清洁工
[解决办法]
加这段代码试试:
private const int WM_IME_CHAR = 0x0286;protected override void WndProc(ref Message m){ switch (m.Msg) { case WM_IME_CHAR: OnKeyPress(new KeyPressEventArgs((char)m.WParam)); break; default: base.WndProc(ref m); break; }}