2012-06-18 11 views
5

Necesito obtener el tamaño del rectángulo del cursor clásico de Windows.Cómo obtener el tamaño del cursor en C#

¿Cómo puedo obtener el tamaño del cursor en C#?

+0

para WPF se puede ver: http://stackoverflow.com/questions/8038853/how-can- i-determine-the-cursor-size-in-wpf –

Respuesta

9

Puede utilizar Cursor.Size:

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

Sí, es así de simple!

Espero que esto ayude!

+0

El tamaño del cursor NO es el tamaño real del cursor. es el tamaño de la imagen. El tamaño del cursor es 32x32 por defecto pero el cursor visual real es 16x20 – Franck

+0

Corrección del tamaño es 13x20 – Franck

2

Un pequeño ejemplo: Reference

 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(); 
    } 
+0

Eso es un montón de código para mostrar cómo usar 'cursor.Size.Width/Height' – Default

+0

@Default: hmm ... true –

+0

Si recibo una sugerencia, podría explicar por qué tiene tanto código o minimizarlo (ya que es un buen ejemplo si desea mostrar un uso real del 'Cursor.Size') – Default

Cuestiones relacionadas