日期:2009-06-07  浏览次数:20334 次

在论坛看到这个帖子,觉得有意思,就实现了一下。其实这个问题以前的高人写了文章的。好像是net_lover吧,记的不是很清楚。

代码如下:


using System;
using System.Windows.Forms;
class test
{
Form frm = new Form();
Button btnOK = new Button();
TextBox txtPsw = new TextBox();

static void Main(string [] args)
{
test temp = new test();
temp.showFrm();
//Console.ReadLine();
}

private void showFrm()
{
btnOK.Text = "确定";
frm.Text = "登陆";
txtPsw.Location = new System.Drawing.Point(10,10);
btnOK.Location = new System.Drawing.Point(txtPsw.Left,txtPsw.Top + txtPsw.Height + 10);
btnOK.Click += new System.EventHandler(btnOKClick);
frm.FormBorderStyle = FormBorderStyle.FixedDialog;
frm.Controls.Add(txtPsw);
frm.Controls.Add(btnOK);
frm.StartPosition = FormStartPosition.CenterScreen;
frm.ShowDialog();
}

private void btnOKClick(object sender, System.EventArgs e)
{
//验证信息
MessageBox.Show(txtPsw.Text);
}
}