窗口欺骗:使鼠标左右击功能相同

c#中怎样让鼠标的左击和鼠标的右击功能相同,也就是说右击所产生的功能左击也同样获得

第1个回答  2013-12-02
容易啊
找到按纽的鼠标事件Mouse_Down 双击进入 然后 调用 按纽的 左击事件 就可以了 我给你个实例 你自己看看
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(56, 80);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(144, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(72, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 16);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
int[] a=new int[]{10,9,8,7,6,5,4,3,2,1};
int i=0,j=a.Length,m=a.Length/2,n;
for(n=0;n<a.Length;n++)
{
if(a[m]==4)
{
textBox1.Text=m.ToString();
break;
}
else
{

if(a[m]<4)
j=m;
if(a[m]>4)
i=m;

}
m=(i+j)/2;

}

}

private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
button1_Click( sender, e);
}

}
}
第2个回答  2013-12-02
不好意思,我不懂C#不过编程还是略懂一些皮毛的,LZ说的问题,如果让我用我会的Delphi来写,我会选择WH_Mouse钩子,里面截取鼠标点击消息并且替换(比如把右键单击消息替换成左键消息,或者把左键消息改称右键)然后再传输出去,这样就能做到LZ的要求了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网