これはフォーム コードで、いくつかの入力をテストするたびに、アプリケーションが開いてすぐに閉じてしまい、何が原因なのかわかりません。
namespace Assignment2
{
public partial class IsmClassForm : Form
{
public IsmClassForm()
{
InitializeComponent();
}
private void IsmClassForm_Load(object sender, EventArgs e)
{
}
protected Student m_student;
protected Course m_course;
protected IsmClassForm m_next;
protected EnrollmentForm m_home;
public bool TestPrerequisites()
{
if (!m_student.Record.MeetsPrerequisites(m_course.Number))
{
MessageBox.Show("The registrar reports that you don't meet the prerequisites for " + m_course.Prefix + m_course.Number.ToString());
m_student.PridePoints = m_student.PridePoints - 5;
m_student.Record.Remove(m_course);
return false;
}
return true;
}
public string Description
{
get
{
return textDescription.Text;
}
set
{
textDescription.Text = value;
}
}
public string Title
{
get
{
return this.Text;
}
set
{
this.Text = value;
}
}
public string Welcome
{
get
{
return labelWelcome.Text;
}
set
{
labelWelcome.Text = value;
}
}
public bool Initialize(Student student, int course, IsmClassForm next, EnrollmentForm home)
{
if (student == null) return false;
m_student = student;
m_next = next;
m_home = home;
m_course = m_student.Record.FindEnrolled(course);
if (m_course == null)
{
return false;
}
labelCourse.Text = m_course.Prefix + "-" + m_course.Number.ToString();
return TestPrerequisites();
}
public enum DropMode
{
FreeDrop, PayDrop, Withdraw, NoDrop
};
DropMode mState = DropMode.FreeDrop;
public DropMode Drop
{
get
{
return mState;
}
set
{
mState = value;
UpdateDrop();
}
}
public void UpdateDrop()
{
switch (Drop)
{
case DropMode.FreeDrop:
buttonDrop.Text = "Drop";
break;
case DropMode.PayDrop:
buttonDrop.Text = "Drop";
break;
case DropMode.Withdraw:
buttonDrop.Text = "Withdraw";
break;
case DropMode.NoDrop:
buttonDrop.Text = "Done";
break;
}
}
protected void buttonDrop_Click(object sender, EventArgs e)
{
switch (Drop)
{
case DropMode.FreeDrop:
m_student.PridePoints = m_student.PridePoints - 5;
m_student.Record.Remove(m_course);
m_course = null;
break;
case DropMode.PayDrop:
m_student.PridePoints = m_student.PridePoints - 10;
m_student.WealthPoints = m_student.WealthPoints - 500;
m_student.Record.Remove(m_course);
m_course = null;
break;
case DropMode.Withdraw:
m_student.PridePoints = m_student.PridePoints - 50;
m_student.WealthPoints = m_student.WealthPoints - 500;
m_course.Grade = "W";
break;
case DropMode.NoDrop:
m_student.WealthPoints = m_student.WealthPoints - 500;
break;
}
Close();
}
protected void IsmClassForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
//The student not having a grade suggest the buttons were ignored
if (m_course != null && m_course.Grade == null)
{
m_course.Grade = "F";
m_student.PridePoints = m_student.PridePoints - 100;
m_student.WealthPoints = m_student.WealthPoints - 500;
}
if (m_next != null) m_next.Show();
else if (m_home != null) m_home.Show();
}
}
そして、ここにいくつかのテスト入力があります:
static void TestIsmClassForm()
{
Student tjt1 = new Student("Travis Todd");
tjt1.Record = new Transcript();
tjt1.Record.Add(new Course(1, 3113, "B", false));
tjt1.Record.Add(new Course(1, 3232, "C", false));
tjt1.Record.Add(new Course(2, 3113, "A", true));
tjt1.Record.Add(new Course(2, 3232, null, true));
tjt1.Record.Add(new Course(2, 4220, null, true));
IsmClassForm f4220 = new IsmClassForm();
IsmClassForm f3232 = new IsmClassForm();
IsmClassForm f4212 = new IsmClassForm();
f4212.Initialize(tjt1, 4212, f3232, null);
f3232.Initialize(tjt1, 3232, f4220, null);
f4220.Initialize(tjt1, 4220, null, null);
f4212.Show();
}
これはプロジェクト内の他のクラスとそのフォームを使用しますが、他の関数はすべて機能し、これがこれまでに見つかった唯一の問題です。明らかに明らかな何かが欠けていますか?
ありがとう、トラヴィス