C#按住鼠标事件 [英] C# Hold down mouse event

查看:584
本文介绍了C#按住鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mousemove事件,它获取光标的位置并将其输出到两个标签(X和Y),当我将鼠标悬停时,该值会动态变化.我有一个mousedown事件,单击该事件时,会将相同的值输出到文本框.如何合并mousedown和mousemove事件,以便在悬停并按住鼠标按钮时,文本框的值会随着移动而动态变化.

I have a mousemove event that takes the position of the cursor and outputs it to two labels (X and Y), the value dynamically changes as I hover around. I have a mousedown event that when clicked, the same values are outputted to a textbox. How can I combine the mousedown and mousemove events so that when I hover AND hold down the mouse button, the textbox value dynamically changes as I move.

推荐答案

您可以在Move事件处理程序中查询鼠标按钮,即:

You can interrogate the mouse buttons in your Move event handler, i.e. :

void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left) {
        String tipText = String.Format("({0}, {1})", e.X, e.Y);
        trackTip.Show(tipText, this, e.Location);
    }
}

这篇关于C#按住鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆