绘制真实光标的问题

时间:2011-07-24 21:57:40

标签: c# bitmap drawing cursor


我正在开发一个screeshot应用程序。我想抓住真正的光标在位图上绘制它。我有两个实现:前者光标显示良好,但它始终是默认光标;而在后者中,光标有时被绘制得很好,有时它不会更新和精心绘制 有没有办法合并这些实施的积极方面?

首先:

Point cursorPosition = Cursor.Position;
if (_bitmapRectangle.Contains(cursorPosition))
{
    Point relativeCursorPosition = new Point(cursorPosition.X - _bitmapRectangle.Location.X, cursorPosition.Y - _bitmapRectangle.Location.Y);
    Cursor.Draw(graphics, new Rectangle(relativeCursorPosition, Cursor.Size));
}

第二

Point cursorPosition = Cursor.Position;
using (Cursor cursor = Cursor.Current)
{ 
   if (_bitmapRectangle.Contains(cursorPosition))
   {
       Point relativeCursorPosition = new Point(cursorPosition.X - _bitmapRectangle.Location.X, cursorPosition.Y - _bitmapRectangle.Location.Y);
       cursor.Draw(graphics, new Rectangle(relativeCursorPosition, cursor.Size));
    }
}

当我没有使用默认光标并且鼠标位于背景窗体上时(屏幕截图形式位于前景中),似乎第二种解决方案效果不佳。

1 个答案:

答案 0 :(得分:0)

Point cursorPosition = Cursor.Position;
if (_bitmapRectangle.Contains(cursorPosition))
{
    Point relativeCursorPosition = new Point(cursorPosition.X - _bitmapRectangle.Location.X, cursorPosition.Y - _bitmapRectangle.Location.Y);
    new Cursor (Cursor.Current.Handle).Draw(graphics, new Rectangle(relativeCursorPosition, Cursor.Size));
}