第一个form 两个输密码的textbox 一个button 点butto就能屏幕锁定
第二个form只有一个text和一个button  
但是我按以下的代码只能实现到 待机状态 不是锁屏啊
form1代码: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 != "")
            {
                Form2 f2 = new Form2();
                pwd = txtpwd1.Text;
                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 = "";
            }
        }
    }
}form2代码: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    {   
        public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            if (f1.pwd==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();     }
}
求高手解决啊  form1的密码传不到form2里面啊 

解决方案 »

  1.   

    form1里面的密码传不到form2里面来啊
    调试 起来也没用啊
    求高手告诉关键代码啊
      

  2.   

     Form2 f2 = new Form2();
    的时候 建议
     Form2 f2 = new Form2(pwd);
    在form2的构造函数里面重载 
    public Form2(string psd)

    this.pwd = psd
    }建议看看窗体传值的资料,有很多种方法
      

  3.   


    我改了   但是效果是 调出了 windows的那个输入开机密码界面  我想实现用我输入textbox
    的密码 来解除屏幕锁定要怎么写代码呢