我正在开发一个程序,该程序让我输入有关船的信息并将该信息添加到列表框中。唯一会出现在列表框中的是船的名称。我需要知道如何在消息框中显示来自其他文本框的所有信息,例如长度、帆尺寸和引擎。任何帮助表示赞赏。
public partial class Form1 : Form
{
ArrayList Home;
public Form1()
{
InitializeComponent();
Home = new ArrayList();
}
private void btnAddApartment_Click(object sender, EventArgs e)
{
//instantiate appartment and add it to arraylist
try
{
Apartment anApartment = new Apartment(txtID.Text, txtAddress.Text, int.Parse(txtYearBuilt.Text), int.Parse(txtBedrooms.Text),
double.Parse(txtSquareFootage.Text), double.Parse(txtPrice.Text), txtFurnished.Text);
Home.Add(anApartment);
ClearText(this);
}
catch (Exception)
{
MessageBox.Show("Make sure you entered everything correctly!", "Error", MessageBoxButtons.OK);
}
}
private void btnAddHouse_Click(object sender, EventArgs e)
{
try
{
House aHouse=new House(txtID.Text, txtAddress.Text, int.Parse(txtYearBuilt.Text), int.Parse(txtBedrooms.Text),
double.Parse(txtSquareFootage.Text), double.Parse(txtPrice.Text),int.Parse(txtGarageCapacity.Text));
Home.Add(aHouse);
AddHouseToListBox();
ClearText(this);
}
catch (Exception)
{
MessageBox.Show("Make sure you entered everything correctly!", "Error", MessageBoxButtons.OK);
}
}
private void ClearText(Control controls)
{
foreach (Control control in controls.Controls)
{
if (control is TextBox)
{
((TextBox)control).Clear();
}
}
}
private void AddHouseToListBox()
{
lstHouse.Items.Clear();
foreach (House person in Home)
{
lstHouse.Items.Add(person.GetAddress());
}
}
private void AddApartmentToListBox()
{
lstApartment.Items.Clear();
foreach (Apartment persons in Home)
{
lstApartment.Items.Add(persons.GetAddress());
}
}