namespace ScreenSaver3
{
    public partial class Form1 : Form
    {
        private static Boolean lockState = false;//保存当前的锁定状态
        private static System.Windows.Forms.Timer appTimer = new Timer(); //计时器
        private static int iTimeLen = 0; //时间计数        public Form1()
        {
            InitializeComponent();
            RegisterAppLockProcess();
        }
       
        private static void RegisterAppLockProcess()
        {
            appTimer.Interval = 1000; //每间隔一秒执行一次检查
            appTimer.Tick += new EventHandler(CheckLockState);            appTimer.Start();            LockMessager lm = new LockMessager();            Application.AddMessageFilter(lm);
        }        private static void CheckLockState(object sender, EventArgs e)  
        {            if (lockState) return;            iTimeLen = iTimeLen + 1;            //当十秒内没有接收到鼠标和键盘的按键,则进行锁定
            if (iTimeLen >= 10)

            {
                ShowLockWindow();                lockState = true;
            }
        }
        private static void ShowLockWindow()
        {
             Form2 frmLock = new Form2();
            frmLock.Show();
        }       internal class LockMessager : IMessageFilter
        {
            public bool PreFilterMessage(ref Message m)
            {
                //如果检测到有鼠标或则键盘被按下的消息,则使计数为0.....
                if (m.Msg == 0x0201 || m.Msg == 0x0100 || m.Msg == 0x0204 || m.Msg == 0x0207 || m.Msg == 0x0216)
                    {iTimeLen = 0;
                    lockState = false;}                return false;
            }
        }
}
}
上面的代码是屏幕保护的,form2就是个屏保,黄色字体部分是设置时间的长短,我想在其他的form上提供可以修改屏保的时间,还有是否启用屏保的项.
form1是主form,我不知道如何使其他form的值可以即时写入主form.比如我某个form上有一个label,我修改了label的值,主form可以即时读到改值.
不好意思,分数有点少,最后的分数了,新手一直在做提问,分数用得太快