这段代码从客户那里获取信息并将其分类到不同的类别(汽车的类型 - 标准或宽)。我想知道如何使用这些信息并能够在位于不同Windows窗体上的listBox
中列出它?
private void buttonSave_Click(object sender, EventArgs e)
{
if (radioWide.Checked)
{
Car newCar = new Wide(textCustomerName.Text, textCarLicense.Text, textCarMake.Text, textCarColour.Text);
currentCar = newCar;
}
else if (radioStandard.Checked)
{
Car newCar = new Standard(textCustomerName.Text, textCarLicense.Text, textCarMake.Text, textCarColour.Text);
currentCar = newCar;
}
"(textCustomerName.Text, textCarLicense.Text, textCarMake.Text, textCarColour.Text);"
- 这些是用户将输入的文本框,radioWide
和radioStandard
是用于为您提供一点可视化的单选按钮
我的列表框现在是空的,并且有不同的列来分隔我从用户收到的信息,这是当前列的代码是什么
//Set up columns in ListView
public static void SetListColumns(ListView listCar)
{
listCar.Columns.Add("Customer Name");
listCar.Columns.Add("Car License Plate");
listCar.Columns.Add("Car Make");
listCar.Columns.Add("Car Colour");
listCar.Columns.Add("Parking Space");
}
//Set up columns in ListView
public static void SetListColumns(ListView listCar)
{
listCar.Columns.Add("Customer Name");
listCar.Columns.Add("Car License Plate");
listCar.Columns.Add("Car Make");
listCar.Columns.Add("Car Colour");
}
//Closing the window using the Close button
private void buttonClose_Click(object sender, EventArgs e)
{
this.Close();
}
//Method to refresh view of the window
private void RefreshView()
{
//Display decarled columns customer variables
ListAllEntries.SetListColumns(listWide);
ListAllEntries.SetListColumns(listStandard);
}
listStandard
和listWide
都是listView
的名称。
唯一的问题是我不确定如何显示userInput并能够在列表框中打印它们
答案 0 :(得分:0)
我希望,我理解你的问题是正确的。您需要在一个表单上收集信息并将其显示在另一个表单中,对吗?
让我们做一些伪编码
class CarInfo
{
// here your properties of the car
}
// here you have your listview with accumulated car data
class CarDisplay : Form
{
private List<CarInfo> _carList = new List<CarInfo>();
// here you popup the data entry form and wire to the saving callback
void buttonShowDataForm_Click (sender, e)
{
// yes - this is best way to show forms because it will dispose them too
using (f = new formDataCollect(CarInfoSubmitCallback))
{
f.ShowModal();
}
}
// here you have your view populated and any operations that you want to add a car
void CarInfoSubmitCallback (CarInfo info)
{
_carList.Add(info);
// optionally here you can do your UI stuff or save to DB, whatever
}
}
// this is your car data entry form
class CarDataEntry : Form
{
private Action<CarInfo> _addCarCallback;
// your constructor passes method that will be called later when user's data is to be saved. In your case, this method will be executed on the form that has your list
public CarDataEntry (Action<CarInfo> callBack)
{
_addCarCallback = callBack;
}
// here you fill your car object and invoke callback, so it executes on another form
void buttonAddCar_Click (sender, e)
{
var ci = new CarInfo();
ci.Name = txtName.Text;
// and so on with properties
. . . . . .
_callBack(ci);
}
}
这是一种方式。我不说没有其他人。您可以使用事件等。