开发者

What event can I change the caret in in a winforms maskedtextbox

Right now, I'm calling the win32 createcaret/showcaret in the keypress event of my masked textbox. That changes it fine. I want the caret to change when the box is entered, though, either by tab or by click.

Unfortunately the enter event or even the invalidate e开发者_如何学Cvent aren't suitable places to change that caret. It doesn't change, maybe because they fire too early.

So anyway, how can I get the caret to change on textbox enter without handling it in the enter event?


You need to add DestroyCaret to your routine, too:

private void Form1_Load(object sender, EventArgs e)
{
  textBox1.GotFocus += new EventHandler(textBox1_GotFocus);
  textBox1.LostFocus += new EventHandler(textBox1_LostFocus);
}

private void textBox1_GotFocus(object sender, EventArgs e)
{
  CreateCaret(textBox1.Handle, IntPtr.Zero, 6, textBox1.Height);
  ShowCaret(textBox1.Handle);
}

private void textBox1_LostFocus(object sender, EventArgs e)
{
  DestroyCaret();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜