using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private Label labelNumLock;
private Label labelCapsLock;
private Label labelScrollLock;
private Label label1;
private Label label2;
private Label label3;
private Label labelInsert;
private Label label4;
///
/// 必要なデザイナ変数です。
///
private System.ComponentModel.IContainer components = null;
///
/// 使用中のリソースをすべてクリーンアップします。
///
/// マネージ リソースが破棄される場合 true、破棄されない場合は false です。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows フォーム デザイナで生成されたコード
///
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
///
private void InitializeComponent()
{
this.labelNumLock = new System.Windows.Forms.Label();
this.labelCapsLock = new System.Windows.Forms.Label();
this.labelScrollLock = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.labelInsert = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// labelNumLock
//
this.labelNumLock.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.labelNumLock.Location = new System.Drawing.Point(90, 11);
this.labelNumLock.Name = "labelNumLock";
this.labelNumLock.Size = new System.Drawing.Size(190, 20);
this.labelNumLock.TabIndex = 0;
this.labelNumLock.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCapsLock
//
this.labelCapsLock.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.labelCapsLock.Location = new System.Drawing.Point(90, 39);
this.labelCapsLock.Name = "labelCapsLock";
this.labelCapsLock.Size = new System.Drawing.Size(190, 20);
this.labelCapsLock.TabIndex = 0;
this.labelCapsLock.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelScrollLock
//
this.labelScrollLock.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.labelScrollLock.Location = new System.Drawing.Point(90, 67);
this.labelScrollLock.Name = "labelScrollLock";
this.labelScrollLock.Size = new System.Drawing.Size(190, 20);
this.labelScrollLock.TabIndex = 0;
this.labelScrollLock.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label1
//
this.label1.Location = new System.Drawing.Point(12, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 20);
this.label1.TabIndex = 0;
this.label1.Text = "NumLock:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.Location = new System.Drawing.Point(12, 39);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 20);
this.label2.TabIndex = 0;
this.label2.Text = "CapsLock:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(12, 67);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 20);
this.label3.TabIndex = 0;
this.label3.Text = "ScrollLock:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// labelInsert
//
this.labelInsert.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.labelInsert.Location = new System.Drawing.Point(90, 95);
this.labelInsert.Name = "labelInsert";
this.labelInsert.Size = new System.Drawing.Size(190, 20);
this.labelInsert.TabIndex = 0;
this.labelInsert.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label4
//
this.label4.Location = new System.Drawing.Point(12, 95);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 20);
this.label4.TabIndex = 0;
this.label4.Text = "Insert:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 126);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.labelInsert);
this.Controls.Add(this.labelScrollLock);
this.Controls.Add(this.label2);
this.Controls.Add(this.labelCapsLock);
this.Controls.Add(this.label1);
this.Controls.Add(this.labelNumLock);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
public Form1()
{
InitializeComponent();
// アプリケーションのアイドル時に呼び出される
// イベント・ハンドラを登録する
Application.Idle += new EventHandler(Application_Idle);
}
// アプリケーションがアイドル時にテキストを更新する
private void Application_Idle(object sender, EventArgs e)
{
// [NumLock]キーの状態を確認する
if (Control.IsKeyLocked(Keys.NumLock))
labelNumLock.Text = "ON";
else
labelNumLock.Text = "OFF";
// [CapsLock]キーの状態を確認する
// ※Keys.Capitalを使用してもよい
if (Control.IsKeyLocked(Keys.CapsLock))
labelCapsLock.Text = "ON";
else
labelCapsLock.Text = "OFF";
// [ScrollLock]キーの状態を確認する
if (Control.IsKeyLocked(Keys.Scroll))
labelScrollLock.Text = "ON";
else
labelScrollLock.Text = "OFF";
// [Insert]キーの状態を確認する
if (Control.IsKeyLocked(Keys.Insert))
labelInsert.Text = "ON";
else
labelInsert.Text = "OFF";
}
}
}