c#屏保功能实现


 public Form1()

 {            

       InitializeComponent();   

}

#region  当一段时间无操作时,自动执行返回初始界面  

 [StructLayout(LayoutKind.Sequential)]

 struct LASTINPUTINFO        

{            

[MarshalAs(UnmanagedType.U4)]  

 public int cbSize;            

[MarshalAs(UnmanagedType.U4)]            

public uint dwTime;        

}        

 

[DllImport("user32.dll")]        

static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);        

static long GetLastInputTime()        

{            

LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();            

vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);            

if (!GetLastInputInfo(ref vLastInputInfo))

    return 0;            

return Environment.TickCount - (long)vLastInputInfo.dwTime;        

}        

#endregion

//加载事件       

private void Form1_Load(object sender, EventArgs e)        

{            

          this.timer1.Start();        

}

//时间控制        

private void timer1_Tick(object sender, EventArgs e)        

{

            if (GetLastInputTime() / 1000 == 10)    //10s            

           {

                label1.Text = "屏保";

            }

            else

                label1.Text = (GetLastInputTime() / 1000).ToString();

           }

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM