有一种形式,其中有控件(文本框,按钮)。
public partial class Form1 : Form
{
public MWLogin()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
//there is text box!
private void txtbox_SelectedIndexChanged(object sender, EventArgs e)
{
if(!String.IsNullorEmpty(txtbox.Text))
{
btnOK.Enabled = true; //for example
}
}
}
并且在单元测试中应该从 txtBox 获取文本,例如:(不正确)
[TestMethod()]
public void Form1Test()
{
try
{
MWLogin target = new MWLogin();
if(MWLogin.ShowDialog() == DialogResult.OK)
{
string a = MWLogin.txtBox.Text; //this is no correct
}
Assert.IsTrue(true);
}
catch (Exception)
{
Assert.Fail();
}
}
请帮忙!如何从txtBox
表单中获取文本(表单中没有静态或公共属性)