-1
我正在製作一個應用程序,根據選中的複選框和單選按鈕來計算總數。但是接下來我想看看在另一個表單或消息箱中選擇了多少個作爲摘要功能。C#顯示次數複選框/無線電盒已被選中
例
User 1 selects: RadioButton 1 and Checkbox 1 and 2,
User 2 selects: radiobox 2 and Checkbox 2
User 3 selects RadioBox 1 and Checkbox 2
結果摘要
RB1= 2
RB2= 1
CB1= 1
CB2= 2
有誰知道代碼是計算有多少次CB和RB已經選擇了什麼?
到目前爲止我的代碼
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int Lunch = 25;
const int Early = 40;
const int Late = 40;
const int Table = 10;
const int Waiter = 20;
int Meal;
int Mealprice;
int Extras;
const int TotalLunch = 1;
int TotalEarly = 1;
int TotalLate = 1;
int TotalWaiters = 1;
int TotalTables = 1;
private void calculateButton_Click(object sender, EventArgs e)
{
int Quantity;
int Finalprice;
if (lunchRadioButton.Checked == true)
{
Meal = Lunch;
TotalLunch.ToString();
}
else if (tableCheckBox.Checked && waiterCheckBox.Checked)
{
Extras = Waiter + Table;
TotalWaiters.ToString();
TotalTables.ToString();
}
else if (waiterCheckBox.Checked)
{
Extras = Waiter;
TotalWaiters.ToString();
}
else if (tableCheckBox.Checked)
{
Extras = Table;
TotalTables.ToString();
}
//Early Evening Meal
if (earlyEveningRadioButton.Checked == true)
{
Meal = Early;
TotalEarly.ToString();
}
else if (tableCheckBox.Checked && waiterCheckBox.Checked)
{
Extras = Table + Waiter;
TotalWaiters.ToString();
TotalTables.ToString();
}
else if (waiterCheckBox.Checked)
{
Extras = Waiter;
TotalWaiters.ToString();
}
else if (tableCheckBox.Checked)
{
Extras = Table;
TotalTables.ToString();
}
//Late evening options
if (lateEveningRadioButton.Checked == true)
{
Meal = Late;
TotalLate.ToString();
}
//Late Evening, Corner table and Dedicated waiter selected.
else if (tableCheckBox.Checked && waiterCheckBox.Checked)
{
Extras = Table + Waiter;
TotalWaiters.ToString();
TotalTables.ToString();
}
//Late Evening and Dedicated waiter selected.
else if (waiterCheckBox.Checked)
{
Extras = Waiter;
TotalWaiters.ToString();
}
//Late Evening and Corner Table
else if (tableCheckBox.Checked)
{
Extras = Table;
TotalTables.ToString();
}
try
{
Quantity = int.Parse(guestTextBox.Text);
Mealprice = (Meal * Quantity);
Finalprice = (Mealprice + Extras);
finalAmountLabel.Text = Finalprice.ToString("C");
}
catch
{
MessageBox.Show("Please enter a quantity in numerical form","Quantity Error!");
}
}
這將是適當的,如果你張貼它作爲評論。 Thx –
將我的代碼添加到原始帖子 – user2884461
您看起來已經連接了最終的按鈕點擊,但當複選框或單選按鈕發生更改時,沒有任何事件發生。如果您使用Windows窗體,當您選擇設計器上的複選框時,在屬性中可以看到所有有效的事件。你可能會想要「OnClick」。點擊時,將特定計數器加1。 – Scottie