Windows里有光标的API函数

        // 新建光标
        [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);
        }

你可能感兴趣的:(windows)