锁屏的模态窗口及所用的主要方法

来源:互联网 发布:字体扫描识别软件 编辑:程序博客网 时间:2024/06/09 20:06

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lock
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public bool T=false;

        private void Form2_Load(object sender, EventArgs e)
        {
            //设置窗体透明度
            this.Opacity = 0.8;
            //设置控件获得焦点
            textBox1.Focus();
           
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "1")
            {
                //要先设置T为true
                T = true;
                this.Close();
            }
            else
            { MessageBox.Show("密码错误!密码:1"); }
           
        }
        //如果不设置Closing方法  按ALT+F4就能把窗口关闭   这也是锁屏最关键的代码。虽然很少!。。。。。。。。
        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (T == false)
            {
                e.Cancel = true;
            }
        }
        //展开label 显示输入框
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (panel1.Height == 0)
            {
                panel1.Height = 100;
            }
            else
            { panel1.Height = 0; }
        }
    }
}