//
新建光标
[DllImport(
"
user32.dll
"
)]
static
extern
bool
CreateCaret(IntPtr hWnd, IntPtr hBitmap,
int
nWidth,
int
nHeight);
//
显示光标
[DllImport(
"
user32.dll
"
)]
static
extern
bool
ShowCaret(IntPtr hWnd);
//
隐藏光标
[DllImport(
"
user32.dll
"
)]
static
extern
bool
HideCaret(IntPtr hWnd);
//
设置光标位置
[DllImport(
"
user32.dll
"
)]
static
extern
bool
SetCaretPos(
int
X,
int
Y);
//
获得输入焦点
[DllImport(
"
user32.dll
"
)]
static
extern
IntPtr SetFocus(IntPtr hWnd);
//
例子:Panel的鼠标释放事件里
void
panel1_MouseUp(
object
sender, MouseEventArgs e)
{
CreateCaret(panel1.Handle, (IntPtr)
null
,
1
,
16
);
SetCaretPos(e.X, e.Y
-
16
/
2
);
ShowCaret(panel1.Handle);
SetFocus(panel1.Handle);
}
转载于:https://www.cnblogs.com/alexusli/archive/2008/12/15/1355209.html