//================================================================================================= // 非クライアント領域でのクリック感知を考慮していない場合のプログラム // // if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left) // // などの部分で正であるならばクリックしている状態と判断される // // // 2013/03/28/否健康食品オワタ //================================================================================================= using System; using System.Windows.Forms; using System.Drawing; class Form00 : Form { //< クリックの状態によって文字が変化するラベル private Label label1; ///
/// 常に処理されるメソッド ///
public void updata() { //< クリック感知系の処理 //< 左クリックを感知したら処理 if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left) { label1.Text = "左クリックされました"; } //< 右クリックを感知したら処理 else if ((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right) { label1.Text = "右クリックされました"; } //< 中心ボタンクリックを感知したら処理 else if ((Control.MouseButtons & MouseButtons.Middle) == MouseButtons.Middle) { label1.Text = "中心クリックされました"; } } //< 以下無関係領域============================================================================ ///
/// コンストラクタ ///
public Form00(){ InitializeComponent(); } private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(96, 137); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(92, 12); this.label1.TabIndex = 0; this.label1.Text = "クリックしていません"; // // Form00 // this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.label1); this.Name = "Form00"; this.Text = "クリック感知"; this.ResumeLayout(false); this.PerformLayout(); } };