我正在尝试填写表格(电影信息,例如标题、年份和类型),然后将其显示在文本框中(启用 = 假)。我有 2 个类和一个表单(带有 2 个文本框(用于用户输入)、2 个按钮、1 个用于注册电影信息,1 个用于在第三个文本框(禁用的那个)中显示信息。
class Movies
{
public string Title { get; set; }
public int Year { get; set; }
public string ReturnMovie()
{
return Title + " (" + Year.ToString() + ")";
}
}
class Genres
{
public string Genre { get; set; }
public string ReturnGenre()
{
return Genre;
}
}
主窗体:
bool btnRegisterClicked = false;
Movies m1 = new Movies();
Genres g1 = new Genres();
private void btnRegister_Click(object sender, EventArgs e)
{
btnRegisterClicked = true;
if (btnRegisterClicked == true)
{
if (txtTitle.Text.Length == 0)
{
MessageBox.Show("Enter a title for the movie.");
btnRegisterClicked = false;
}
else if (txtYear.Text.Length < 4)
{
MessageBox.Show("Enter a valid year.");
btnRegisterClicked = false;
}
else if (chkGenre.SelectedIndex == -1)
{
MessageBox.Show("Select the genre(s) of the movie.");
btnRegisterClicked = false;
}
else
{
txtTitle.Text = m1.Title;
txtYear.Text = m1.Year.ToString();
chkGenre.Text = g1.Genre;
}
txtTitle.Clear();
txtYear.Clear();
chkGenre.ClearSelected();
}
}
private void btnShow_Click(object sender, EventArgs e)
{
txtShow.Text = m1.ReturnMovie() + g1.ReturnGenre();
}
}
我究竟做错了什么 ?