当前位置:网站首页>C#(二十八)之C#鼠标事件、键盘事件
C#(二十八)之C#鼠标事件、键盘事件
2022-07-06 03:39:00 【camellias_】
今天看下鼠标事件、键盘事件。
1:鼠标事件分为两种:
EventArgs:MouseEnter/MouseLeave 等
MouseEventArgs:MouseDoubleClick、MouseDown、MouseUp、MouseHover、MouseMove。
private void button1_MouseEnter(object sender, EventArgs e)
{
label1.Text = "按钮进入事件";
}
private void button1_MouseLeave(object sender, EventArgs e)
{
label1.Text = "按钮离开事件";
}
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
label2.Text = "双击窗体事件";
}
private void button2_MouseDown(object sender, MouseEventArgs e)
{
label2.Text = "按下按钮2";
}
private void button2_MouseUp(object sender, MouseEventArgs e)
{
label2.Text = "松开按钮2";
}
private void button2_MouseHover(object sender, EventArgs e)
{
label3.Text = "鼠标在按钮2上停留了一段时间";
}
private void button2_MouseMove(object sender, MouseEventArgs e)
{
label4.Text = "鼠标在按钮2上经过";
}
2:键盘事件
KeyEventArgs:
KeyPressEventArgs:
KeyPress:必须是焦点在控件上时才好用。(按下并松开发生)
KeyDown:是在按下按键时发生
KeyUp:是在抬起按键时发生
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
label1.Text += e.KeyChar;
}
键盘事件与鼠标事件类似,这里只是看了一部分概念,相关案例以后遇到再补充。
测试使用代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace mianbanGc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_MouseEnter(object sender, EventArgs e)
{
label1.Text = "按钮进入事件";
}
private void button1_MouseLeave(object sender, EventArgs e)
{
label1.Text = "按钮离开事件";
}
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
label2.Text = "双击窗体事件";
}
private void button2_MouseDown(object sender, MouseEventArgs e)
{
label2.Text = "按下按钮2";
}
private void button2_MouseUp(object sender, MouseEventArgs e)
{
label2.Text = "松开按钮2";
}
private void button2_MouseHover(object sender, EventArgs e)
{
label3.Text = "鼠标在按钮2上停留了一段时间";
}
private void button2_MouseMove(object sender, MouseEventArgs e)
{
label4.Text = "鼠标在按钮2上经过";
}
public string str = "";
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
str += e.KeyChar;
label5.Text += e.KeyChar;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
}
}
有好的建议,请在下方输入你的评论。
欢迎访问个人博客
https://guanchao.site
欢迎访问小程序:

边栏推荐
- Multi project programming minimalist use case
- Distributed service framework dobbo
- Blue Bridge Cup - Castle formula
- Microkernel structure understanding
- Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
- Schnuka: what is visual positioning system and how to position it
- Research on cooperative control of industrial robots
- [practice] mathematics in lottery
- SAP ALV color code corresponding color (finishing)
- UDP reliable transport protocol (quic)
猜你喜欢

数据分析——seaborn可视化(笔记自用)

Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)

给新人工程师组员的建议

Svg drag point crop image JS effect

Four logs of MySQL server layer

2. GPIO related operations
![[meisai] meisai thesis reference template](/img/14/b39e1db0b5b35702508068e028ee5a.jpg)
[meisai] meisai thesis reference template

Overview of super-resolution reconstruction of remote sensing images

2.13 weekly report

Record the process of reverse task manager
随机推荐
An article about liquid template engine
Four logs of MySQL server layer
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
Pointer for in-depth analysis (problem solution)
The solution of permission denied (750 permissions should be used with caution)
Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project
Differential GPS RTK thousand search
SWC介绍
简述C语言中的符号和链接库
2.2 STM32 GPIO操作
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
RT-Thread--Lwip之FTP(2)
Safety science to | travel, you must read a guide
SAP ALV单元格级别设置颜色
Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
Schnuka: 3D vision detection application industry machine vision 3D detection
【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
Edcircles: a real time circle detector with a false detection control translation
Pelosi: Congress will soon have legislation against members' stock speculation