private void subjectpagenextbtn_Click(object sender, EventArgs e)
{
TextBox[] subjectnamearray = new TextBox[] { subjectname1, subjectname2, subjectname3, subjectname4, subjectname5, subjectname6 };
int i = 0;
while (i <= numofsubjects.SelectedIndex)
{
if (subjectnamearray[i].Text.Trim() == string.Empty)
{
MessageBox.Show("Please fill out all textboxes.", "Error Message");
i = i + 1;
return;
}
}
i = 0;
string[] subjects = new string[numofsubjects.SelectedIndex];
List<string> datatablesubjectnamearray = new List<string>();
this.Hide();
var TaskPage = new Task_Page(subjectnamearray,datatablesubjectnamearray,numofsubjects.SelectedIndex);
TaskPage.Closed += (s, args) => this.Close();
TaskPage.Show();
TaskPage.StartPosition = FormStartPosition.Manual;
TaskPage.Location = new Point(this.Location.X, this.Location.Y);
while (i < numofsubjects.SelectedIndex)
{
datatablesubjectnamearray.Add(subjectnamearray[i] + "Weighting");
datatablesubjectnamearray.Add(subjectnamearray[i] + "Marks");
/*http://csharp.net-informations.com/collection/list.htm*/
i = i + 1;
}
Task_Page taskpage = new Task_Page(subjectnamearray, datatablesubjectnamearray, numofsubjects.SelectedIndex);
}
这是我拥有的表单上的一个按钮的代码,该按钮用于收集用户的主题和用户的主题数,并且我基本上还为要访问的数据表的标题制作了一个数组在下一个表单上创建。我还将值,subjectnamearray,datatablesubjectnamearray,numofsubjects.SelectedIndex传递给TaskPage。因此,“任务页面”是单击按钮时想要访问的页面。我也希望传递这些值,但是当我单击按钮时,它冻结了,甚至无法关闭应用程序。我必须按Visual Studio上的“停止”按钮。但是我不知道为什么会冻结。
答案 0 :(得分:1)
您的第一个while循环似乎是问题所在。您陷入无限循环。我在代码中看不到其他问题。
您的代码如下:
private void subjectpagenextbtn_Click(object sender, EventArgs e)
{
TextBox[] subjectnamearray = new TextBox[] { subjectname1, subjectname2, subjectname3, subjectname4, subjectname5, subjectname6 };
int i = 0;
while (i <= numofsubjects.SelectedIndex)
{
if (subjectnamearray[i].Text.Trim() == string.Empty)
{
MessageBox.Show("Please fill out all textboxes.", "Error Message");
i = i + 1;
return;
}
}
我想如果您将代码更改为此:
private void subjectpagenextbtn_Click(object sender, EventArgs e)
{
TextBox[] subjectnamearray = new TextBox[] { subjectname1, subjectname2, subjectname3, subjectname4, subjectname5, subjectname6 };
int i = 0;
while (i <= numofsubjects.SelectedIndex)
{
if (subjectnamearray[i].Text.Trim() == string.Empty)
{
MessageBox.Show("Please fill out all textboxes.", "Error Message");
return;
}
i = i + 1;
}
它应该可以解决Visual Studio崩溃的问题。如果没有,我建议关闭VS,重新启动计算机,然后重试。祝你好运!