我上面的回答错误了。Form没有Form(string temp)这样的构着函数。你需要的效果以前一位高人写了文章讨论过。具体你可以搜搜。我写了个例子程序如下: ----------------------------------------------------------- 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(); }
-----------------------------------------------------------
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);
}
}csc test.cs就可以了。
参考:ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemWindowsFormsFormMethodsTopic.htm