Reputation: 73
I am creating an application like a kiosk ordering machine that allows customers to purchase hoagies and pizzas.
There are five forms included. The main form, the hoagie form, the pizza form, the size form, and the toppings form.
The main form has two buttons:
When a customer clicks on the hoagie button, the hoagie form opens. When a customer clicks on the pizza form, the pizza form opens. These two forms each have different choices accordingly.
Hoagie form has 3 buttons such as hoagie1 / hoagie2 / hoagie3.
Pizza form has 3 buttons such as pizza1 / pizza2 / pizza3.
When a button is clicked, the size form is opened. The size form has 3 buttons such as small / medium / large. The size form is shared by both the hoagie form and the pizza form.
When a button is clicked, the toppings form will open which contains different toppings. One for hoagies and one for pizzas.
This is where I am stuck. If i clicked on hoagie button previously then on hoagie1 button and then on small button, then the hoagie toppings form should open. If I clicked on pizza button previously then on pizza1 button and then on small button, then the pizza toppings form should open. How would I go about this?
This is what I have for the small button click event from the size form.
private void btnSmall_Click(object sender, EventArgs e)
{
frmToppings frmToppings = new frmToppings();
if (//hoagies)
{
frmToppings.DrawHoagieToppingsForm();
}
else (//pizzas)
{
frmToppings.DrawPizzaToppingsForm();
}
}
Upvotes: 1
Views: 207
Reputation: 15
Im not sure if this is what you need, your explanation is a bit confusing
So you have 5 forms, and you have a button in each of the forms that should open another form? If you are in form1, there is a button that opens form2 or form3 And if you are in form2, there is a button that opens form3 or form 4 ?
So in this example is the code that could be in the main form1, it has 2 buttons, one opens the pizza, the other opens the hoagies forms when you click on them
private void openform2_Click(object sender, EventArgs e) //the action of clicking the button that has the name of "openform2"
{
Form2 pizza = new Form2(); //the form2 is your second form, it will opened when openform2 button is clicked
pizza.Show();
}
private void openform3_Click(object sender, EventArgs e) //the action of clicking the button that has the name of "openform3"
{
Form3 hoagies = new Form3();
hoagies.Show();
}
Upvotes: 0
Reputation: 799
In your constructor of your size form you could pass through an enum value containing details of the form you are on. Put this into your size form:
public enum FoodType {
Pizza,
Hoagies
}
And then your size form constructor and private field:
private FoodType type { get; set; }
public SizeForm(FoodType type)
{
this.type = type;
}
And then in your button click handler
private void btnSmall_Click(object sender, EventArgs e)
{
frmToppings frmToppings = new frmToppings();
if (type == FoodType.Hoagies)
{
frmToppings.DrawHoagieToppingsForm();
}
else (type == FoodType.Pizza)
{
frmToppings.DrawPizzaToppingsForm();
}
}
And using this from your Pizza or Hoagies form:
SizeForm form = new SizeForm(FoodType.Pizza);
form.ShowDialog();
You could also pass through some delegate that holds your frmToppings.DrawHoagieToppingsForm();
or frmToppings.DrawPizzaToppingsForm();
and then calls this delegate in your btnSmall_Click
Upvotes: 1