All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
AjaxPro与服务器端交互过程中如何传值_[AJAX教程]
delphi单行编辑框组件(TEdit)使用实例
让GridView有新增记录的功能_[Asp.Net教程]
使用ASP.NET,MVC,和LINQ建立一个简单的博客,-,Part,3_[Asp.Net教程]
asp.net,2.0的文件上传(突破上传限制4M)_[Asp.Net教程]
动态网页PHP编程中八种常见的文件操作方式_php资料_编程技术
深入ASP.NET数据绑定(中)——数据双向绑定机理_[Asp.Net教程]
GDI+ 绘制折线图分析网站流量
SQL转ACCESS解决自动编号问题_[SQL,Server教程]
C#网络应用编程基础练习题与答案(四)_.net资料_编程技术
Reading number is top 10 pictures
The world's ten biggest attractions of inventory super the moon
住院一星期,检测费两万
鸡蛋的新玩法
Black and white also sexy--YanLiu1
乳娘帕梅拉安德森3
Chinese paper-cut grilles art appreciation6
9.3阅兵全景图3-外国方阵梯队和坦克方阵梯队
小学生作文又现神作,你不得不佩服
Abdominal hit by iron--HangZhou best driver parking save passengers
西班牙山村小景5
Download software ranking
打鸟视频
天龙八部最新服务端
Ashlynn Video3
linux初级教程
Unix video tutorial4
网络管理员第三版
matrix1
Boxer vs Yellow5
Unix video tutorial1
Eclipse-CALMSANNY (second edition)
qq published in(发表于) 2014/7/11 9:22:47 Edit(编辑)
C#教程:MouseDown和MouseUp事件

C#教程:MouseDown和MouseUp事件

C#教程:MouseDown和MouseUp事件

MouseDown和MouseUp事件

1.MouseDown事件

当鼠标指针位于控件上并按下鼠标键时发生。

语法:

public event MouseEventHandler MouseDown

参数说明如下。

MouseEventHandler:表示将处理窗体、控件或其他组件的MouseDown、MouseUp或 MouseMove事件的方法。

MouseEventHandler委托事件语法:

public delegate void MouseEventHandler (Object sender,MouseEventArgs e)

参数说明如下。

sender:事件源。

e:包含事件数据的MouseEventArgs。

MouseEventArgs用来构造函数对数,其公共属性及说明如表1所示。



表1 MouseEventArgs参数属性及说明

示例

MouseDown事件的使用

本示例单击鼠标右键,弹出快捷菜单。示例运行结果如图1所示。



图1 MouseDown事件的使用

private void Form1_MouseDown(object sender, MouseEventArgs e)

{

OnMouseDown = True;

if (e.Button == MouseButtons.Right)

{

this.contextMenuStrip1.Show(this, new Point(e.X, e.Y));

}

}

完整程序代码如下:

★ ★★★★frmMouse.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _2_05

{

public partial class frmMouse : Form

{

public frmMouse()

{

InitializeComponent();

}

public bool G_OnMouseDown = false;

public Point lastPoint = Point.Empty;

public string G_str_color = "black";

public Pen pen;

public Graphics graphics;

//当你拖拽鼠标处理的和序,当没有上一点时,你目当所按下的点就是上一个点

//目当所按下的点就是CurrPoint,使用您所选反背景色画笔pen从lastPointi画一条直线,然后将

//上一个点LastPoint的值设为目前点currPoint

private void Form1_MouseMove(object sender, MouseEventArgs e)

{

}

//当鼠标离开时把布尔变量设为false;

private void Form1_MouseUp(object sender, MouseEventArgs e)

{

G_OnMouseDown = false;

}

//将布尔变量OnMouseDown设为true 按下鼠标右键时显示菜单

private void Form1_MouseDown(object sender, MouseEventArgs e)

{

G_OnMouseDown = true;

if (e.Button == MouseButtons.Right)

{

this.contextMenuStrip1.Show(this, new Point(e.X, e.Y));

}

}

private void frmMouse_Load(object sender, EventArgs e)

{

}

}

}

★ ★★★★frmMouse..Designer.cs窗体设计文件完整程序代码★★★★★

namespace _2_05

{

partial class frmMouse

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);

this.blackToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

this.whiteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

this.redToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

this.greenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

this.blueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

this.contextMenuStrip1.SuspendLayout();

this.SuspendLayout();

//

// contextMenuStrip1

//

this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {

this.blackToolStripMenuItem,


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.