C#實(shí)現(xiàn)鼠標(biāo)左右鍵切換效果
更新時(shí)間:2022年12月21日 10:02:55 作者:芝麻粒兒
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)鼠標(biāo)左右鍵切換功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
實(shí)踐過(guò)程
效果
代碼
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> /// 必需的設(shè)計(jì)器變量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的資源。 /// </summary> /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗體設(shè)計(jì)器生成的代碼 /// <summary> /// 設(shè)計(jì)器支持所需的方法 - 不要 /// 使用代碼編輯器修改此方法的內(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; }
到此這篇關(guān)于C#實(shí)現(xiàn)鼠標(biāo)左右鍵切換效果的文章就介紹到這了,更多相關(guān)C#鼠標(biāo)左右鍵切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C# Winform實(shí)現(xiàn)石頭剪刀布游戲
這篇文章主要為大家詳細(xì)介紹了Winform實(shí)現(xiàn)石頭剪刀布游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01利用C#實(shí)現(xiàn)獲取當(dāng)前設(shè)備硬件信息
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)獲取當(dāng)前設(shè)備硬件信息的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-03-03C#基礎(chǔ):Dispose()、Close()、Finalize()的區(qū)別詳解
本篇文章是對(duì)c#中的Dispose()、Close()、Finalize()的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05C#實(shí)現(xiàn)自定義打印文字和圖片的示例代碼
本文主要介紹了C#實(shí)現(xiàn)自定義打印文字和圖片的示例代碼,C#中打印其實(shí)就是自己繪圖+調(diào)用系統(tǒng)打印函數(shù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04FtpHelper實(shí)現(xiàn)ftp服務(wù)器文件讀寫(xiě)操作(C#)
這篇文章主要為大家詳細(xì)介紹了FtpHelper實(shí)現(xiàn)ftp服務(wù)器文件讀寫(xiě)操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03