namespace Test {
partial class MouseClickEnhanceForm {
/// <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>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent() {
this.Init = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// Init
//
this.Init.Location = new System.Drawing.Point(107, 12);
this.Init.Name = "Init";
this.Init.Size = new System.Drawing.Size(75, 23);
this.Init.TabIndex = 0;
this.Init.Text = "初始化";
this.Init.UseVisualStyleBackColor = true;
this.Init.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.AcceptsReturn = true;
this.textBox1.AcceptsTab = true;
this.textBox1.Location = new System.Drawing.Point(12, 41);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox1.Size = new System.Drawing.Size(287, 356);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "点击窗口进行测试";
//
// MouseClickEnhanceForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(369, 457);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.Init);
this.Name = "MouseClickEnhanceForm";
this.Text = "仿遨游双键鼠标功能";
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button Init;
private System.Windows.Forms.TextBox textBox1;
}
}
另一个文件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test {
/// <summary>
/// 实现(1)按住右键然后点击左键,(2)按住左键然后点击右键
/// 注意: 请在窗体中添加一个TextBox(变量名称为textBox1)
/// 和Button(变量名为:botton1)
/// </summary>
public partial class MouseClickEnhanceForm : Form {
public MouseClickEnhanceForm() {
InitializeComponent();
}
/// <summary>
/// 鼠标状态
/// </summary>
public enum MouseButtonsState {
LeftDown = 1,
LeftUp,
RightDown,
RightUp
} ;
//当前按键状态
private int btnState = -1;
//为了在TextBox中换行,使用此家伙,用TextBox.Text="/n"方式换行不好使,
//不是鼠标功能的一部分只是为了换行显示信息
private List<string> list = new List<string>();
private void OutText(String text) {
list.Add(text);
this.textBox1.Lines = list.ToArray();
}
private void Form1_MouseDown(object sender, MouseEventArgs e) {
switch (e.Button) {
case MouseButtons.Left:
if (btnState==(int)MouseButtonsState.RightDown) {
this.OutText("1. 按住右键,点击左键");
}
btnState = (int) MouseButtonsState.LeftDown;
this.OutText("2. 左键,MouseDown事件");
break;
case MouseButtons.Right:
if (btnState==(int)MouseButtonsState.LeftDown) {
this.OutText("3. 按住左键,点击右键");
}
btnState = (int) MouseButtonsState.RightDown;
this.OutText("4. 右键,MouseDown事件");
break;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e) {
this.btnState = -1;
this.OutText("5. 初始btnSate值为: -1");
}
private void button1_Click(object sender, EventArgs e) {
this.textBox1.Text = "";
btnState = -1;
}
}
}