小编Gun*_*nar的帖子

我需要帮助显示C#的多个文本框?

我正在尝试使用WinForms制作邮件标签程序,您可以在其中输入您的姓名,州,城市等,然后单击按钮,它会显示您在每个框中输入的所有文本并将其显示在一个标签上.我很接近但是当我运行我的程序时,这些单词之间没有空格.这是我的代码:

namespace Mail_Label_Program
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnDisplay_Click(object sender, EventArgs e)
        {
            lblMessage.Text = txtFirst.Text + txtLast.Text;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            //This closes the program.
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //This clears all textbox forms.
            txtFirst.Text = string.Empty;
            txtLast.Text = string.Empty;
            txtCity.Text = string.Empty;
            txtStreet.Text = string.Empty;
            txtState.Text = string.Empty;
            txtZip.Text = string.Empty;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# textbox

3
推荐指数
1
解决办法
213
查看次数

汽车租赁计划C#

我的学校项目需要帮助.我一直在努力,最终想出如何输出开始里程表和结束里程表=总里程驱动.对于总费用,我需要每天增加15美元的租金,加上每英里0.12美元.我该怎么做?这是我现在的代码:

//Step 1: Declaring variables to store our information.
decimal beginningOdometerDecimal;
decimal endingOdometerDecimal;
decimal rentedDecimal;
decimal totalSaleDecimal;
decimal averageSalesDecimal;
decimal carsReturned;
decimal totalMilesDecimal;
decimal finalCostDecimal;

//Step 2: Get the information from the user.
beginningOdometerDecimal = Decimal.Parse(txtBegin.Text);
endingOdometerDecimal = Decimal.Parse(txtEnd.Text);
rentedDecimal = Decimal.Parse(txtRent.Text);

//Step 3: Mathmatematical Calculations.
totalMilesDecimal = endingOdometerDecimal - beginningOdometerDecimal;
finalCostDecimal = totalMilesDecimal * (Decimal)0.12 + rentedDecimal + 15;
Run Code Online (Sandbox Code Playgroud)

如你所见,我使用finalCostDecimal等于totalmilesdecimal*$ 0.12 + rentedDecimal + 15.我不认为我使用了正确的代码.有人可以帮我吗?我被困住并尝试了很多.谢谢!

c#

2
推荐指数
1
解决办法
1725
查看次数

我不能发消息框,有错误吗?

我想加入我的租车计划.抱歉有这些问题.我仍在学习 :).所以我希望我的表单显示一个错误消息,当您不输入数字或文本框为空时弹出.我试过了:

 //If nothing is inserted in text, error box.
        int value = 0;
        if (string.IsNullOrWhitespace(txtBegin.Text) || !int.TryParse(txtBegin.Text, out value)) // Test for null or empty string or string is not a number
            MessageBox.Show("Please enter a number!");
        else
            MessageBox.Show(string.Format("You entered: {0}!", value));
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:'string'不包含'IsNullOrWhitespace'的定义.谁能帮我?

c#

2
推荐指数
1
解决办法
104
查看次数

为什么我的BMI平均代码无法正常工作?

我试图计算一些人的平均BMI.当我运行此代码时,每次单击计算按钮时平均BMI都会下降.为什么?

float feet;
float inches;
float height;
float weight;
float bmi;
float averagebmi;

try
{
    //Get user input.
    feet = float.Parse(txtFeet.Text);
    inches = float.Parse(txtInches.Text);
    weight = float.Parse(txtWeight.Text);

    //Calculations.
    inches += feet * 12;
    height = inches * (float)0.0254;
    weight = weight * (float)0.453592;
    bmi = weight / (height * height);

    //Manager Calculations.
    totalPeople += 1;
    bmi += 1;
    averagebmi = bmi / totalPeople;
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
114
查看次数

标签 统计

c# ×4

textbox ×1