博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

c#隐藏TextBox中闪烁的光标

Posted on 2011-05-31 11:22  hyruur  阅读(565)  评论(1编辑  收藏  举报

方案:调用Windows API

1> 将TextBox的TabStop设置为false;

2> 在程序中相应位置加入下列代码

 

using System.Runtime.InteropServices;
……
[DllImport(
"user32", EntryPoint = "HideCaret")]
private static extern bool HideCaret(IntPtr hWnd);
……
在TextBox的MouseDown事件中添入:
HideCaret(((TextBox)sender).Handle);