このコードをループして合計費用の値を加算する方法を教えてください。あなたは、単にユーザーフォームが上に行くにしたくない場合はこのコードをループして合計費用の値に加算する方法
private void totalCostTextBox_TextChanged(object sender, EventArgs e)
{
if (totalCostTextBox.Text == "€ 0,00")
MessageBox.Show("hey!");
}
が、その後、calculateBtn_Click()
の一番下に追加します:
//end of if statements and variables
// Illustrate results
costLabel.Text = "Registration: " + registrationFee.ToString("c") +
" \nLodging Fee: " + lodgingFee.ToString("c") + " x " +
days.ToString() + " days = " + (lodgingFee * days).ToString("c");
decimal totalCost = registrationFee + (lodgingFee * days);
if (totalCost == 0)
{
MessageBox.Show("total cost was zero! Re-Enter data");
}
else
{
totalCostTextBox.Text = totalCost.ToString("c");
}
ので、ユーザー
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Workshop_Selector
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateBtn_Click(object sender, EventArgs e)
{
// Declaring variables to zero so they can found in a list
decimal registrationFee = 0;
decimal days = 0;
decimal lodgingFee = 0;
if (workshopListBox.SelectedIndex != -1 && locationListBox.SelectedIndex != -1) //when list items selected are not below zero
{
//From workshop list data inputs calculate the variables
switch (workshopListBox.SelectedIndex)
{
case 0: // in the first case of "Handling Stress" the workshop lasts for 3 days and costs 1000 euro
days = 3;
registrationFee = 1000;
break; //Case finisher
case 1: // in the second case of "Time Mgnt" the workshop lasts for 3 days and costs 800 euro
days = 3;
registrationFee = 800;
break;
case 2: // in the third case of "Supervision skills" the workshop lasts for 3 days and costs 1500 euro
days = 3;
registrationFee = 1500;
break;
case 3: // in the fourth case of "Negotiation" the workshop lasts for 5 days and costs 1300 euro
days = 5;
registrationFee = 1300;
break;
case 4: // in the fifth case of "How to Interview" the workshop lasts for 3 days and costs 500 euro
days = 1;
registrationFee = 500;
break;
}
//From location list data inputs calculate the variables
switch (locationListBox.SelectedIndex)
{
case 0: //In the first case in the location list lodging fee per day in Galway is 150 euro
lodgingFee = 150;
break;
case 1: //In the second case in the location list lodging fee per day in Dublin is 225 euro
lodgingFee = 225;
break;
case 2: //In the third case in the location list lodging fee per day in Limerick is 175 euro
lodgingFee = 175;
break;
case 3: //In the fourth case in the location list lodging fee per day in Cork is 300 euro
lodgingFee = 300;
break;
case 4: //In the fifth case in the location list lodging fee per day in Athlone is 175 euro
lodgingFee = 175;
break;
case 5: //In the sixth case in the location list lodging fee per day in Ennis is 150 euro
lodgingFee = 150;
break;
}
}
//end of if statements and variables
// Illustrate results
costLabel.Text = "Registration: " + registrationFee.ToString("c") +
" \nLodging Fee: " + lodgingFee.ToString("c") + " x " +
days.ToString() + " days = " + (lodgingFee * days).ToString("c");
totalCostTextBox.Text = (registrationFee + (lodgingFee * days)).ToString("c");
}
}
}
Winforms、WPF、ASP ..は何をターゲットにしていますか? __Always__あなたの質問に正しくタグを付けてください! - 書式設定がオフです。感嘆符を付けないでください。そして__one__ '?'しましょう。 TextBoxの 'TextChanged'イベントを見てください。 – TaW
申し訳ありません、私の最初の質問です。私はメッセージボックスを手に入れる方法を見つけました。しかし、私はこのコードをループして総コスト値に加えることができます – jjmackey9
今はまったく異なる問題のように聞こえます。 – TaW