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 locked
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string pwd = "";
private void button1_Click(object sender, EventArgs e)
{
if ((txtpwd1.Text == txtpwd2.Text) && txtpwd1.Text != "")
{
pwd = txtpwd1.Text;
Form2 f2 = new Form2(pwd);
this.Hide();
f2.Show();
}
if (txtpwd1.Text == "" || txtpwd2.Text == "")
{
MessageBox.Show("密碼不能為空");
txtpwd1.Text = "";
txtpwd2.Text = "";
}
if(txtpwd1.Text!=txtpwd2.Text)
{
MessageBox.Show("兩次密碼不一致,請重新輸入");
txtpwd1.Text = "";
txtpwd2.Text = "";
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
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;
using System.Runtime.InteropServices;
namespace locked
{
public partial class Form2 : Form
{
string str = String.Empty;
public Form2(string psd)
{
InitializeComponent();
this.str = psd;
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
if (str == txtpwd.Text)
{
LockWorkStation();
this.Dispose();
}
else
{
txtpwd.Text = "密碼錯誤,請重新輸入";
}
}
private void Form2_Load(object sender, EventArgs e)
{
Location = new Point(0, 0);
Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
this.TopMost = true;
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
//e.Cancel = true;
}
[DllImport("User32.dll ")]
public static extern void LockWorkStation();
private void txtpwd_Click(object sender, EventArgs e)
{
this.txtpwd.Text = "";
}
}
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。