Control.IsKeyLocked(Keys) 方法

定义

确定 Caps Lock、Num Lock 或 Scroll Lock 键是否有效。

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

参数

keyVal
Keys

Keys 枚举的 Caps Lock、Num Lock 或 Scroll Lock 成员。

返回

Boolean

如果指定的一个或多个键有效,则为 true;否则为 false

例外

keyVal 参数指一个键,而不是 CAPS LOCK、NUM LOCK 或 SCROLL LOCK。

示例

下面的代码示例显示一个消息框,指示指定键是否在此示例中 (Caps Lock 键,) 有效。

#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

注解

使用 IsKeyLocked 属性可确定 CAPS LOCK、NUM LOCK 或 SCROLL LOCK 键是单独打开还是组合打开。

适用于