当前位置:网站首页>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
欢迎访问小程序:

边栏推荐
- 2、GPIO相关操作
- 【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
- 给新人工程师组员的建议
- 数据分析——seaborn可视化(笔记自用)
- MPLS experiment
- [meisai] meisai thesis reference template
- Crazy, thousands of netizens are exploding the company's salary
- JS Vanke banner rotation chart JS special effect
- 1. New project
- Distributed service framework dobbo
猜你喜欢

暑期刷题-Day3

The next industry outlet: NFT digital collection, is it an opportunity or a foam?

2.13 weekly report

2.2 fonctionnement stm32 GPIO

2、GPIO相关操作

Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation

BUAA calculator (expression calculation - expression tree implementation)

BUAA计算器(表达式计算-表达式树实现)

js凡客banner轮播图js特效

SWC介绍
随机推荐
[American competition] mathematical terms
Map sorts according to the key value (ascending plus descending)
Mysqldump data backup
Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
How do we make money in agriculture, rural areas and farmers? 100% for reference
JS Vanke banner rotation chart JS special effect
Esbuild & SWC: a new generation of construction tools
Explore pointers and pointer types in depth
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
11. Container with the most water
Blue Bridge Cup - day of week
3.1 rtthread 串口设备(V1)详解
IPv6 comprehensive experiment
[padding] an error is reported in the prediction after loading the model weight attributeerror: 'model' object has no attribute '_ place‘
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
Flask learning and project practice 9: WTF form verification
The solution of permission denied (750 permissions should be used with caution)
Indicator system of KQI and KPI
Suggestions for new engineer team members
深入刨析的指针(题解)