• 大小: 2.15MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-08
  • 语言: C#
  • 标签: C#  Winform  锁屏  

资源简介

超时锁屏功能,前提: 系统为WinForm实现,中有一个主窗体; 1、当用户键鼠无操作超过10分钟,则锁定该系统(当前项目); 2、锁屏后弹出用户登录界面,登陆界面两个输入框,用户名、密码(均为simed); 3、锁屏后用户无法对系统其他页面做任何操作,仅能在登录界面录入用户名、密码,实现登录; 4、登陆成功后,关闭登录界面,系统恢复可录入状态; 5、主界面为Winform,一个Richtextbox,能够演示锁屏后无法操作,登录后可继续操作即可; 6、登录失败则提示“用户名或密码错误”,继续停留在登陆界面,录入的用户名保留,密码框清空,密码框获得焦点; 目前设置30秒就超时。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LockScreenCS
{
    public partial class FmLogin : Form
    {
        public FmLogin()
        {
            InitializeComponent();
        }
        public FmLogin(bool bl) //超时登录走这个
        {
            InitializeComponent();
            isTimer = bl;
        }

        /***************获取鼠标键盘未操作时间***************************/
        [StructLayout(LayoutKind.Sequential)]
        public struct LASTINPUTINFO
        {
            [MarshalAs(UnmanagedType.U4)]
            public int cbSize;
            [MarshalAs(UnmanagedType.U4)]
            public uint dwTime;
        }
        [DllImport(“user32.dll“)]
        public static extern bool GetLastInputInfo(ref    LASTINPUTINFO plii);


        public long getIdleTick()
        {
            LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
            vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
            if (!GetLastInputInfo(ref    vLastInputInfo)) return 0;
            return Environment.TickCount - (long)vLastInputInfo.dwTime;
        }
        /***************获取鼠标键盘未操作时间***************************/

        public static bool isTimer = false;//判断是否是超时了
        private void Login_Load(object sender EventArgs e)
        {
            this.timer1.Interval = 10000;//定时器
            this.timer1.Enabled = true;//启动
        }

        private void btnLogin_Click(object sender EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUser.Text.Trim())||string.IsNullOrEmpty(txtPwd.Text.Trim()))
            {
                MessageBox.Show(“用户名或密码不能为空!“);
                txtUser.Focus();
            }
            else
            {
                if (txtUser.Text.Trim() == “simed“ && txtPwd.Text.Trim() == “simed“)
                {
                    this.Hide();
                    if (isTimer == false)//正常登录
                    {
                        FmMain fm = new FmMain(); //跳转
                        fm.Show();
                    }
                }
                else
                {
                    MessageBox.Show(“用户名或密码错误!“);
                    txtPwd.Text = ““;
                    txtPwd.Focus();//获得焦点
                }
            }
        }

        private void btnCancel_Click(object sender EventArgs e)
        {
            txtUser.Text = ““;
            txtPwd.Text = ““;
        }

        /// 
        /// keyDown判断是否是enter键,进行登录事件
        /// 

        /// 
        /// 
        private void txtPwd_KeyDown(object sender KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)//enter键 ==(char)13也可
            {
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        187  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\App.config

     文件      13824  2013-07-17 16:56  LockScreenCSPro22\LockScreenCS\bin\Debug\LockScreenCS.exe

     文件        187  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\bin\Debug\LockScreenCS.exe.config

     文件      38400  2013-07-17 16:56  LockScreenCSPro22\LockScreenCS\bin\Debug\LockScreenCS.pdb

     文件      22984  2013-07-18 09:14  LockScreenCSPro22\LockScreenCS\bin\Debug\LockScreenCS.vshost.exe

     文件        187  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\bin\Debug\LockScreenCS.vshost.exe.config

     文件        490  2012-06-06 02:06  LockScreenCSPro22\LockScreenCS\bin\Debug\LockScreenCS.vshost.exe.manifest

     文件       5371  2013-07-17 16:55  LockScreenCSPro22\LockScreenCS\FmLogin.cs

     文件       5439  2013-07-17 15:48  LockScreenCSPro22\LockScreenCS\FmLogin.Designer.cs

     文件       6011  2013-07-17 10:57  LockScreenCSPro22\LockScreenCS\FmLogin.resx

     文件        530  2013-07-17 10:57  LockScreenCSPro22\LockScreenCS\FmMain.cs

     文件       2235  2013-07-17 10:57  LockScreenCSPro22\LockScreenCS\FmMain.Designer.cs

     文件       5817  2013-07-17 10:57  LockScreenCSPro22\LockScreenCS\FmMain.resx

     文件       4446  2013-07-17 15:48  LockScreenCSPro22\LockScreenCS\LockScreenCS.csproj

     文件       1308  2013-07-16 13:49  LockScreenCSPro22\LockScreenCS\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6931  2013-07-17 15:48  LockScreenCSPro22\LockScreenCS\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        703  2013-07-18 09:14  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.csproj.FileListAbsolute.txt

     文件       1098  2013-07-17 16:47  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.csproj.GenerateResource.Cache

     文件      13824  2013-07-17 16:56  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.exe

     文件        180  2013-07-17 16:47  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.FmLogin.resources

     文件        180  2013-07-17 16:47  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.FmMain.resources

     文件      38400  2013-07-17 16:56  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.pdb

     文件        180  2013-07-17 16:47  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.Properties.Resources.resources

     文件        180  2013-07-17 16:47  LockScreenCSPro22\LockScreenCS\obj\Debug\LockScreenCS.TestTimer.resources

     文件          0  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件        623  2013-07-17 15:48  LockScreenCSPro22\LockScreenCS\Program.cs

     文件       1362  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\Properties\AssemblyInfo.cs

     文件       2876  2013-07-16 12:50  LockScreenCSPro22\LockScreenCS\Properties\Resources.Designer.cs

............此处省略170个文件信息

评论

共有 条评论