Control.IsKeyLocked(Keys) Metod

Definition

Avgör om CAPS LOCK-, NUM LOCK- eller SCROLL LOCK-tangenten är i kraft.

public:
 static bool IsKeyLocked(System::Windows::Forms::Keys keyVal);
public static bool IsKeyLocked(System.Windows.Forms.Keys keyVal);
static member IsKeyLocked : System.Windows.Forms.Keys -> bool
Public Shared Function IsKeyLocked (keyVal As Keys) As Boolean

Parametrar

keyVal
Keys

CAPS LOCK, NUM LOCK eller SCROLL LOCK-medlemmen i Keys uppräkningen.

Returer

trueom den angivna nyckeln eller nycklarna är i kraft; annars . false

Undantag

Parametern keyVal refererar till en annan nyckel än CAPS LOCK, NUM LOCK eller SCROLL LOCK.

Exempel

I följande kodexempel visas en meddelanderuta som anger om den angivna nyckeln (Caps Lock-nyckeln i det här fallet) gäller.

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
int main()
{
   if (Control::IsKeyLocked( Keys::CapsLock )) {
      MessageBox::Show( "The Caps Lock key is ON." );
   }
   else { 
      MessageBox::Show( "The Caps Lock key is OFF." );
   }

}
using System;
using System.Windows.Forms;

public class CapsLockIndicator
{
    public static void Main()
    {
        if (Control.IsKeyLocked(Keys.CapsLock)) {
            MessageBox.Show("The Caps Lock key is ON.");
        }
        else {
            MessageBox.Show("The Caps Lock key is OFF.");
        }
    }
}

' To compile and run this sample from the command line, proceed as follows:
' vbc controliskeylocked.vb /r:System.Windows.Forms.dll /r:System.dll 
' /r:System.Data.dll /r:System.Drawing.dll

Imports System.Windows.Forms

Public Class CapsLockIndicator
   
    Public Shared Sub Main()
        if Control.IsKeyLocked(Keys.CapsLock) Then
            MessageBox.Show("The Caps Lock key is ON.")
        Else
            MessageBox.Show("The Caps Lock key is OFF.")
        End If
    End Sub
End Class

Kommentarer

IsKeyLocked(Keys) Använd metoden för att avgöra om CAPS LOCK-, NUM LOCK- eller SCROLL LOCK-tangenterna är aktiverade, antingen individuellt eller i kombination.

Gäller för