`
xmlspy
  • 浏览: 31882 次
社区版块
存档分类
最新评论

按住左键点击右键,和按住右键点击左键,c#源码

阅读更多
可以下载附件,vs2005解决方案

文件一:Form1.cs

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;
    }
  }
}


文件二: Form1.Designer.cs
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;
	}
}


1
2
分享到:
评论

相关推荐

    按住左键点击右键,和按住右键点击左键,c#

    博文链接:https://xmlspy.iteye.com/blog/184112

    Direct3D_Smart引擎V1.0(C#源码)

    Smart3D引擎V1.0(C#源码) 功能介绍: 这是一个完全用C#写的引擎,全部是自己实现的,大约有1万行代码。 目标是构造一个健壮、高效、动态的3D引擎(不仅限于游戏)。渲染框 架借鉴了OGRE/Axiom,去掉了跨平台和跨...

    C#中在pictureBox1中实时画矩形框.

    C#中在pictureBox1中实时画矩形框.

    系统热键控制按设定毫秒数于下一秒开始计时模拟鼠标单击(C# 源码)

    通过本C#程序源码可学习: 程序窗体最大化/最小化还原到系统托盘 调用系统DLL(user32.dll)设定全局热键控制程序,模拟鼠标单击操作 调用timer控件计时 Thread线程控制 FileStream文件流读写操作

    SmartC#3D引擎V0.1源码2012929

    SmartC#3D引擎V0.1源码 功能介绍: 这是一个完全用C#写的引擎,全部是自己实现的,大约有1万行代码。 目标是构造一个健壮、高效、动态的3D引擎(不仅限于游戏)。渲染框 架借鉴了OGRE/Axiom,去掉了跨平台和跨图形...

    C# 画线,鼠标轨迹等源码

    实现了画固定图形,以及跟踪鼠标移动轨迹。按住鼠标左键在规定区域内移动鼠标即可画出任意图形。

    C# API模拟鼠标键盘操作(QQ巧遇卡广告机)实例

    摘要:C#源码,系统相关,模拟鼠标,API C#API模拟鼠标键盘操作(QQ巧遇卡广告机)实例源码,打开QQ巧遇卡,运行程序,选中 巧遇卡坐标后面的单选按钮,再按住 Z 键,此时就是选坐标,其他一样,之后关掉对话框点开始就...

    鼠标拖动图像在窗体上移动,C#源码下载

    摘要:C#源码,图形图像,图像拖动 鼠标拖动图像在窗体上移动,C#源码下载,打开图像后,在图像上按住鼠标左键移动,可将图像拖动到窗口内的任意位置,有兴趣的C#爱好者请下载源代码。

    让C#在程序运行窗口中拖动组件(图片缩略图)

    摘要:C#源码,菜单窗体,缩略图,拖动组件 让C#在程序运行窗口中拖动组件(图片缩略图),这是个有意思的源码哦,那些看似图片缩略图的东西在窗口中可以随意被拖动,鼠标放上去后按住鼠标左键就可以拖动它们,在窗口内...

    Mouse Paint C#画出点线效果

    摘要:C#源码,图形图像,画线 Mouse Paint C#画出点线效果,按住鼠标左键在窗体中移动,即可画出线条,这些线条由一定规则的点组成,压缩包内的两个源码实例相差不大,都是画线的实例。

    无标题栏,无边框的窗体拖动 C#代码实例

    摘要:C#源码,菜单窗体,窗口拖动 无标题栏,无边框的窗体拖动 C#代码实例,为方便测试,弄成了黑色背景,没了关闭按钮,关闭时请按Alt+F4,另外你可以在黑色区域按住鼠标左键拖动本窗口到任意地方,拖动无边框窗体的...

    二维CAD二次开发控件(免费版)

    文字和尺寸标注;元素属性设置;长度、角度、面积的查询; DXF输出;提供交换文件和二次开发接口。适用于 CAD/CAM/GIS/GPS等相关图形软件开发。软件价格:试用版本免费相关文档:--发布日期:2003.07.29===========...

Global site tag (gtag.js) - Google Analytics