简体   繁体   English

如何使用c#突出显示鼠标指针位置

[英]how to highlight the mouse pointer position using c#

I need a simple mouse pointer highlighter in the form of a circle centered at the mouse pointer. 我需要一个简单的鼠标指针荧光笔,以鼠标指针为中心的圆形。 Using Invalidate() in the below code causes rear circles along the path as flickers. 在下面的代码中使用Invalidate()会导致沿着路径的后方圆圈闪烁。 They are hardly noticeable. 它们几乎不引人注意。 Moreover, it doesn't draw the circle at the moment i rest the mouse. 而且,在我休息鼠标时,它不会绘制圆圈。

What event should I consider to draw the circle at the position the mouse pointer is rested (tried other mouse events as well)? 我应该考虑在鼠标指针休息位置绘制圆圈的事件(尝试其他鼠标事件)?

Is there a way to refresh the drawing without using invalidate()? 有没有办法刷新绘图而不使用invalidate()?

 private void Form1_MouseMove(object sender, MouseEventArgs e)
    {

        SolidBrush myBrush = new SolidBrush(Color.Yellow);
        Graphics gg = this.CreateGraphics();
        Point p = new Point();
        p = e.Location;
        int radius = 10;
        float x = p.X - radius;
        float y = p.Y - radius;
        float width = 5 * radius;
        float height = 5 * radius;
        gg.FillEllipse(myBrush, x, y, width, height);
        gg.dispose();
        Invalidate();

    }

First turn on DoubleBuffered = true; 首先打开DoubleBuffered = true;

Then this should do: 然后这应该做:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    Invalidate();
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
    float radius = 10f;
    Point pt = PointToClient(Cursor.Position);
    e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
    e.Graphics.FillEllipse(Brushes.Yellow, pt.X - radius, 
                           pt.Y - radius, radius * 2, radius * 2);

}

Since you are trying to highlight a spot on the background you may want to use a semi-transparent Color like this: 由于您尝试在背景上突出显示某个点,因此您可能需要使用半透明颜色,如下所示:

 using (SolidBrush brush = new SolidBrush(Color.FromArgb(160, Color.Yellow)))
     e.Graphics.FillEllipse(brush, pt.X - radius, pt.Y - radius, radius * 2, radius * 2);

You may want to play with other values for alpha than 160. 您可能希望使用alpha的其他值而不是160。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用emguCV C#控制头部移动的鼠标指针? - how to control mouse pointer with head movement using emguCV C#? Metro App-使用C#/ VB获取触摸/鼠标的绝对指针位置 - Metro App - Getting the absolute pointer position of touch / mouse using C# / VB 使用C#在WPF中设置鼠标指针位置的最佳方法是什么 - What is the best possible method to set the position of Mouse Pointer in WPF using C# 将Webbrowser用于C#时如何找到鼠标的位置? - How to find the position of the mouse when using webbrowser for C#? 在C#中使用鼠标位置旋转图片 - Rotating a picture using mouse position in C# 如何重置鼠标光标位置C# - How to reset mouse cursor position c# 如何使用c#查找带有鼠标指针的最近打开的/当前活动的文件的路径 - How to Find the path of an recently opened/ Currently Active file with a Mouse pointer in it using c# 用 C# 更换鼠标 position - Changing mouse position with C# 如何使用c#在外部应用程序窗口的鼠标指针下获取对象/元素/控件? - How to get Object/Element/Control under mouse pointer of a external application window using c#? 如何使用C#检测鼠标指针所在的文本? - How can I detect the text where the mouse pointer is, using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM