问题遇到的现象和发生背景
预期实现C#winform窗口汉字书写笔记效果,并在窗口标题上实时显示鼠标坐标
已经可以完美实现,汉字书写功能,窗口标题上实现鼠标坐标功能未实现
问题相关代码,请勿粘贴截图
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//鼠标坐标
}
bool isMouseDown = false; //鼠标是否按下
Point pointMouse = new Point();
protected override void OnMouseDown(MouseEventArgs e)
{
pointMouse = e.Location; //鼠标坐标
isMouseDown = true; //标记鼠标已经按下
}
protected override void undermousemove(MouseEventArgs e)
{
Point clientMouse = e.Location; //获取鼠标窗体客户区坐标
Point screenMouse = PointToScreen(clientMouse); //获取鼠标屏幕坐标
this.Text = string.Format("鼠标窗体坐标:({0},{1}) 鼠标屏幕坐标:({2},{3})",
clientMouse.X, clientMouse.Y, screenMouse.X, screenMouse.Y);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (isMouseDown)
{
using (Graphics G = this.CreateGraphics()) //获取窗体绘制表面
{
G.SmoothingMode = SmoothingMode.AntiAlias;//开启消除锯齿
using (Pen pen = new Pen(Color.Black, 3f))//创建宽度为3像素的黑色画笔
{
G.DrawLine(pen, pointMouse, e.Location); //绘制线段
pointMouse = e.Location; //重新设置鼠标坐标
}
}
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
isMouseDown = false; //标记鼠标未按下
}
}
}
运行结果及报错内容
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 CS0115 “Form1.undermousemove(MouseEventArgs)”: 没有找到适合的方法来重写 WindowsFormsApp8 C:\Users\fligh\source\repos\WindowsFormsApp8\Form1.cs 35 活动