当前位置:网站首页>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
欢迎访问小程序:
边栏推荐
- How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
- SWC introduction
- js凡客banner轮播图js特效
- 记录一下逆向任务管理器的过程
- 1.16 - 校验码
- [slam] lidar camera external parameter calibration (Hong Kong University marslab) does not need a QR code calibration board
- Indicator system of KQI and KPI
- Deno介绍
- An article will give you a comprehensive understanding of the internal and external components of "computer"
- Pytorch基础——(2)张量(tensor)的数学运算
猜你喜欢
BUAA magpie nesting
Overview of super-resolution reconstruction of remote sensing images
RT thread -- FTP of LwIP (2)
Esbuild & SWC: a new generation of construction tools
蓝色样式商城网站页脚代码
[practice] mathematics in lottery
1.16 - 校验码
施努卡:3d视觉检测应用行业 机器视觉3d检测
Blue Bridge Cup - Castle formula
Pointer written test questions ~ approaching Dachang
随机推荐
出现Permission denied的解决办法(750权限谨慎使用)
施努卡:视觉定位系统 视觉定位系统的工作原理
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
Flask learning and project practice 8: introduction and use of cookies and sessions
Pointer written test questions ~ approaching Dachang
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
A brief introduction to symbols and link libraries in C language
2.2 STM32 GPIO操作
Pelosi: Congress will soon have legislation against members' stock speculation
How do we make money in agriculture, rural areas and farmers? 100% for reference
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
Cubemx 移植正点原子LCD显示例程
11. Container with the most water
Pytorch基础——(2)张量(tensor)的数学运算
MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
3.2 detailed explanation of rtthread serial port device (V2)
SAP ALV cell level set color
Safety science to | travel, you must read a guide