C#實現(xiàn)鼠標左右鍵切換效果
更新時間:2022年12月21日 10:02:55 作者:芝麻粒兒
這篇文章主要為大家詳細介紹了如何利用C#實現(xiàn)鼠標左右鍵切換功能,文中的示例代碼講解詳細,對我們學習C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實踐過程
效果
代碼
public partial class Form1 : Form { public Form1() { InitializeComponent(); } [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SwapMouseButton")] public extern static int SwapMouseButton(int bSwap); private void button1_Click(object sender, EventArgs e) { SwapMouseButton(1); } private void button2_Click(object sender, EventArgs e) { SwapMouseButton(0); } }
partial class Form1 { /// <summary> /// 必需的設計器變量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的資源。 /// </summary> /// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗體設計器生成的代碼 /// <summary> /// 設計器支持所需的方法 - 不要 /// 使用代碼編輯器修改此方法的內(nèi)容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(34, 52); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "左鍵"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(136, 52); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 1; this.button2.Text = "右鍵"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(247, 100); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "左右鍵的切換"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; }
到此這篇關于C#實現(xiàn)鼠標左右鍵切換效果的文章就介紹到這了,更多相關C#鼠標左右鍵切換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
C#基礎:Dispose()、Close()、Finalize()的區(qū)別詳解
本篇文章是對c#中的Dispose()、Close()、Finalize()的區(qū)別進行了詳細的分析介紹,需要的朋友參考下2013-05-05FtpHelper實現(xiàn)ftp服務器文件讀寫操作(C#)
這篇文章主要為大家詳細介紹了FtpHelper實現(xiàn)ftp服務器文件讀寫操作,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03