2014-02-08 47 views
0

简单的问题。我想截取屏幕的一部分而不用鼠标指针。我试过这个,但它不起作用。光标在屏幕截图时不会隐藏

private void button1_Click(object sender, EventArgs e) 
{ 
    Cursor.Hide(); 
    gfxScreenshot.CopyFromScreen(//...); 
    Cursor.Show(); 
} 

上面的代码在button_click事件上。我在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时,指针在图像上可见。
我只能假设隐藏方法比CopyFromScreen方法慢... 有什么办法让它在没有1秒延迟的情况下工作?

+1

这是一个环境问题。你有一个非常不寻常和相当破碎的视频驱动程序。或者其他任何实用程序混淆鼠标光标的外观。 –

+0

你是对的!我没有一个正规的游标。我禁用了它,现在它效果很好。谢谢:) – Ouranos

回答

0

获取光标位置,移动到(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); 
     } 
    } 
} 
+0

我试过这个,它也没有工作: private void button1_Click(object sender,EventArgs e) { Point mouse_Temp = new Point(Cursor.Position.X,Cursor.Position.Y); Cursor.Position = new Point(0,0); gfxScreenshot.CopyFromScreen(// ...); Cursor.Position = mouse_Temp; } – Ouranos

+0

我用新代码更新了我的答案。代码起作用。我测试了它。一探究竟。 –

+0

谢谢你。你写的代码比我目前能够理解的更先进:P我是一个初学者。没关系,我解决了它。我的代码不工作,因为我已经放在我的鼠标光标上的自定义指针。 – Ouranos