共用方式為


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 鍵是開啟的,無論是個別還是組合。

適用於