在論壇看到這個帖子,覺得有意思,就實現(xiàn)了一下。其實這個問題以前的高人寫了文章的。好像是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); } }
|