我想实现这么个功能,鼠标在FORM中不动5秒后,就隐藏掉。然后移动鼠标就显示。
请问怎么完成?
3Q!
请问怎么完成?
3Q!
解决方案 »
- sqlserver存储过程 winform与控制台程序 慢
- Newtonsoft.Json怎么解析json?json字符的格式不是固定的,所以没法写一个对应的类
- 如何发布带水晶报表的asp
- 本人初学VC#,请各位帮忙一个关于添加事件的问题!!!1
- 为什么在InstallShield 10中创建快捷方式不能显示中文?
- 真晕~Access和SQL的语句怎么大不一样?
- c# 的各个类的名称空间如何修改?我的都在默认的下面,太乱
- 求《c#数据安全手册》和另一本书的代码。
- C# 类中base和this的问题,求帮忙
- 原来一直用VS2010,装了VS6.0的几个扩展程序之后,2010就不能用。。
- cookie判定的问题
- 谁能给个C/S项目我练习练习吧
要把鼠标移到FORM中才可以!
为什么呢?
3Q!
[DllImport("user32.dll" , EntryPoint = "ShowCursor" , CharSet = CharSet.Auto)]
public static extern void ShowCursor(int status);status:0/1 :隐藏/显示
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication5
{
public partial class Form1 : Form
{
/// <summary>
/// 获取鼠标闲置时间
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO
{
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}
/// <summary>
/// 获取鼠标闲置时间
/// </summary>
/// <param name="plii"></param>
/// <returns></returns>
[DllImport("user32.dll")]
public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); /// <summary>
/// 设置鼠标状态的计数器(非状态)
/// </summary>
/// <param name="bShow">状态</param>
/// <returns>状态技术</returns>
[DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)]
public static extern int ShowCursor(bool bShow);
public Form1()
{
InitializeComponent();
//定时期
System.Windows.Forms.Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = 100;
timer.Tick += new EventHandler(timer_Tick); }
//鼠标状态计数器
int iCount = 0;
void timer_Tick(object sender, EventArgs e)
{
//鼠标状态计数器>=0的情况下鼠标可见,<0不可见,并不是直接受api函数影响而改变
long i=getIdleTick() ;
if (i > 5000)
{
while (iCount >= 0)
{
iCount=ShowCursor(false);
}
}
else
{
while (iCount < 0)
{
iCount = ShowCursor(true);
}
}
}
/// <summary>
/// 获取闲置时间
/// </summary>
/// <returns></returns>
public long getIdleTick()
{
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
return Environment.TickCount - (long)vLastInputInfo.dwTime;
}
}
}
Cursor.Show();