如何在 C# 中获取光标的大小

本文关键字:光标 获取 | 更新日期: 2023-09-27 18:37:28

我需要获取经典窗口光标的矩形大小。

如何在 c# 中获取光标的大小?

如何在 C# 中获取光标的大小

您可以使用

Cursor.Size:

int cursorWidth = Cursor.Size.Width;
int cursorHeight = Cursor.Size.Height;

是的,就是这么简单!

希望这有帮助!

一个小例子:

       if(this.Cursor != Cursors.Hand & 
         Cursor.Current == Cursors.Default)
       {
          // Draw the cursor stretched.
          Graphics graphics = this.CreateGraphics();
          Rectangle rectangle = new Rectangle(
            new Point(10,10), new Size(cursor.Size.Width * 2, 
            cursor.Size.Height * 2));
          cursor.DrawStretched(graphics, rectangle);

      // Draw the cursor in normal size.
      rectangle.Location = new Point(
      rectangle.Width + rectangle.Location.X, 
        rectangle.Height + rectangle.Location.Y);
      rectangle.Size = cursor.Size;
      cursor.Draw(graphics, rectangle);
      // Dispose of the cursor.
      cursor.Dispose();
   }

有关深入信息,请访问 MSDN链接: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.size.aspx