为您的表单提供前一个表单可用于获取选择的业务属性。在下面的示例中,它只允许选择单个项目。但是您可以调整它以允许用户在关闭表单之前选择项目列表。
public class BaseSelectionForm : Form
{
public string Selection { get; protected set; }
}
public class MainForm : Form
{
public List<string> Selections { get; set; }
private void ButtonClick(object sender, EventArgs e)
{
using (var dialog = new CategoryForm())
{
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Selections.Add(dialog.Item);
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
}
}
public class CategoryForm : BaseSelectionForm
{
private void ButtonClick(object sender, EventArgs e)
{
using (var dialog = new SubCategoryForm())
{
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Selection = "This Category Name > " + dialog.Item;
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
}
}
public class SubCategoryForm : BaseSelectionForm
{
private void ButtonClick(object sender, EventArgs e)
{
Selection = "Brown Shirt / $34.00";
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}