您的位置:首页 > 其它

如何在自定义的控件中使用输入法

2008-03-20 16:04 197 查看
1.需要将Control.ImeMode设置为On

2.处理OnKeyPress

public class EditorControl : System.Windows.Forms.Control

{

public EditorControl()

{

//开启输入法模式

this.ImeMode = System.Windows.Forms.ImeMode.On;

}

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)

{

base.OnPaint(e);

//将Text显示出来

System.Windows.Forms.TextRenderer.DrawText(e.Graphics,

this.Text,

new System.Drawing.Font("微软雅黑",30),

new System.Drawing.Point(0,0),

System.Drawing.Color.Black);

}

protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)

{

base.OnKeyPress(e);

this.Text += e.KeyChar;

this.Invalidate();

e.Handled = true;//注意这里,如果这里没设置,输入中文会重复。

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐