如何突出显示系统光标?就像许多屏幕录制应用程序一样。理想情况下,我想在它周围显示一个光环。谢谢
问问题
6792 次
1 回答
7
对于纯托管的解决方案,以下代码将在桌面上的当前鼠标光标位置绘制一个椭圆。
Point pt = Cursor.Position; // Get the mouse cursor in screen coordinates
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
g.DrawEllipse(Pens.Black, pt.X - 10, pt.Y - 10, 20, 20);
}
例如,通过使用计时器,您可以每 20 毫秒更新一次鼠标位置并绘制新的万圣节(椭圆)。
我可以想到其他更有效的方法,但它们需要使用系统挂钩的未管理代码。查看 SetWindowsHookEx 了解更多信息。
更新:这是我在评论中描述的解决方案示例,这只是粗略的,可用于测试目的。
public partial class Form1 : Form
{
private HalloForm _hallo;
private Timer _timer;
public Form1()
{
InitializeComponent();
_hallo = new HalloForm();
_timer = new Timer() { Interval = 20, Enabled = true };
_timer.Tick += new EventHandler(Timer_Tick);
}
void Timer_Tick(object sender, EventArgs e)
{
Point pt = Cursor.Position;
pt.Offset(-(_hallo.Width / 2), -(_hallo.Height / 2));
_hallo.Location = pt;
if (!_hallo.Visible)
{
_hallo.Show();
}
}
}
public class HalloForm : Form
{
public HalloForm()
{
TopMost = true;
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
BackColor = Color.LightGreen;
TransparencyKey = Color.LightGreen;
Width = 100;
Height = 100;
Paint += new PaintEventHandler(HalloForm_Paint);
}
void HalloForm_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Black, (Width - 25) / 2, (Height - 25) / 2, 25, 25);
}
}
于 2010-04-12T18:57:34.290 回答