C#中获得系统当前鼠标的图案

本文介绍了一个使用C#实现的简单应用程序,该程序能够捕获并绘制当前显示的鼠标光标。通过调用GetCursorInfo方法并利用DllImport属性引入user32.dll库,程序可以获取鼠标的当前位置及是否可见等信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Text;
None.gif
using System.Windows.Forms;
None.gif
using System.Runtime;
None.gif
using System.Runtime.InteropServices;
None.gif
None.gif
None.gif
namespace Neicun
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
public partial class Form1 : Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        [StructLayout(LayoutKind.Sequential)]
InBlock.gif        
struct CURSORINFO
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
public int cbSize;
InBlock.gif            
public int flags;
InBlock.gif            
public IntPtr hCursor;
InBlock.gif            
public Point ptScreenPos;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [DllImport(
"user32.dll")]
InBlock.gif        
static extern bool GetCursorInfo(out CURSORINFO pci);
InBlock.gif
InBlock.gif        
private const int CURSOR_SHOWING = 0x00000001;
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button1_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif
InBlock.gif            CURSORINFO vCurosrInfo;
InBlock.gif            vCurosrInfo.cbSize 
= Marshal.SizeOf(typeof(CURSORINFO));
InBlock.gif            GetCursorInfo(
out vCurosrInfo);
InBlock.gif            
if ((vCurosrInfo.flags & CURSOR_SHOWING) != CURSOR_SHOWING) return;
InBlock.gif            Cursor vCursor 
= new Cursor(vCurosrInfo.hCursor);
InBlock.gif            Graphics vGraphics 
= Graphics.FromHwnd(Handle);
InBlock.gif            Rectangle vRectangle 
= new Rectangle(003232);
InBlock.gif            vGraphics.FillRectangle(
new SolidBrush(BackColor), vRectangle);
InBlock.gif            vCursor.Draw(vGraphics, vRectangle);
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/zbqy/archive/2007/04/27/729362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值