C# 光标不在';不要在截图时隐藏
简单的问题。我想拍一张屏幕上没有鼠标指针的部分截图。我试过了,但没用C# 光标不在';不要在截图时隐藏,c#,cursor,screenshot,C#,Cursor,Screenshot,简单的问题。我想拍一张屏幕上没有鼠标指针的部分截图。我试过了,但没用 private void button1_Click(object sender, EventArgs e) { Cursor.Hide(); gfxScreenshot.CopyFromScreen(//...); Cursor.Show(); } 上面的代码在一个按钮点击事件中。我在timer_tick事件中传输了代码,除了Cursor.Hide()之外,并使计时器的间隔为1000。单击按钮时计时器启动
private void button1_Click(object sender, EventArgs e)
{
Cursor.Hide();
gfxScreenshot.CopyFromScreen(//...);
Cursor.Show();
}
上面的代码在一个按钮点击事件中。我在timer_tick事件中传输了代码,除了Cursor.Hide()之外,并使计时器的间隔为1000。单击按钮时计时器启动
private void button1_Click(object sender, EventArgs e)
{
Cursor.Hide();
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
gfxScreenshot.CopyFromScreen(//...);
Cursor.Show();
timer1.Stop();
}
它是这样工作的,但我必须等1秒钟。当我将间隔减少到100时,指针在图像上可见。我只能假设hide方法比CopyFromScreen方法慢。。。
有没有办法让它在没有1秒延迟的情况下工作???获取光标位置,移动到(0,0),截图,放回光标。代码使用API工作:
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Test1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public static implicit operator Point(POINT point)
{
return new Point(point.X, point.Y);
}
}
public Form1()
{
InitializeComponent();
POINT lpPoint;
//Get current location of cursor
GetCursorPos( out lpPoint );
//Move to (0,0)
SetCursorPos( 0, 0 );
//Take screenshot
//gfxScreenshot.CopyFromScreen(//...);
MessageBox.Show("just for create a delay", "Debug", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Put back cursor
SetCursorPos( lpPoint.X, lpPoint.Y );
}
}
}
这是一个环境问题。你有一个非常不寻常的,相当破碎的视频驱动程序。或者其他任何会破坏鼠标光标外观的工具。你说得对!我没有一个固定的光标。我禁用了它,现在它工作得很好。谢谢:)我试过了,但也没用:私有无效按钮1_点击(对象发送者,事件参数e){Point mouse_Temp=new Point(Cursor.Position.X,Cursor.Position.Y);Cursor.Position=new Point(0,0);gfxScreenshot.CopyFromScreen(/…);Cursor.Position=mouse_Temp;}我用新代码更新了答案。代码是有效的。我测试过了。看看,谢谢你。你写的代码比我现在能理解的更高级:P我完全是个初学者。没关系,我解决了。我的代码无法运行,因为我在鼠标光标上放置了一个自定义指针。欢迎使用。因为你是新来的,我想说的是,如果我的代码对你有帮助的话,很高兴给它打分。祝你好运