简体   繁体   English

C# - string.IsNullOrEmpty 不适用于特定文本框

[英]C# - string.IsNullOrEmpty not working for a specific textbox

I'm just learning to program and I'm trying to create a program to calculate weight & balance for an aircraft.我只是在学习编程,我正在尝试创建一个程序来计算飞机的重量和平衡。 When you first load this form, I want all the textboxes specified to have a value of 0. I'm running into an issue where one of the boxes is remaining blank and not inputting 0 (Bag Weight).当您第一次加载此表单时,我希望所有指定的文本框的值都为 0。我遇到了一个问题,其中一个框保持空白且未输入 0(行李重量)。 Maybe its something very simple I'm missing?也许我错过了一些非常简单的东西? Please see below code:请看下面的代码:

tb1legBW.text = This is the bag weight I'm referring too. tb1legBW.text = 这也是我指的包重量。

// This is setting the textbox values to 0 if they are blank. 
        if (string.IsNullOrEmpty(tb1LegOEW.Text) || string.IsNullOrEmpty(tb1LegPW.Text) || string.IsNullOrEmpty(tb1LegBW.Text) ||
            string.IsNullOrEmpty(tb1LegFW.Text) || string.IsNullOrEmpty(tb1LegFuel.Text) || string.IsNullOrEmpty(tb1LegEquip.Text) ||
            string.IsNullOrEmpty(tb1LegAWI.Text) || string.IsNullOrEmpty(tb1LegFB.Text) || string.IsNullOrEmpty(tb1LegCont.Text) ||
            string.IsNullOrEmpty(tb1LegMTOW.Text) || string.IsNullOrEmpty(tb1LegGW.Text) || string.IsNullOrEmpty(tb1LegGD.Text) ||
            string.IsNullOrEmpty(tb1LegMLW.Text) || string.IsNullOrEmpty(tb1LegLW.Text) || string.IsNullOrEmpty(tb1LegLGD.Text))

        {
            tb1LegOEW.Text = "0";
            tb1LegPW.Text = "0";
            tb1LegBW.Text = "0";
            tb1LegFW.Text = "0";
            tb1LegFuel.Text = "0";
            tb1LegEquip.Text = "0";
            tb1LegAWI.Text = "0";
            tb1LegFB.Text = "0";
            tb1LegCont.Text = "0";
            tb1LegMTOW.Text = "0";
            tb1LegGW.Text = "0";
            tb1LegGD.Text = "0";
            tb1LegMLW.Text = "0";
            tb1LegLW.Text = "0";
            tb1LegLGD.Text = "0";
        }

When I run the program the bag weight textbox is blank, unlike the others.当我运行程序时,包重量文本框是空白的,与其他的不同。 Picture is attached: When Program is ran附图:程序运行时

If someone could please give me some insight on what is happening?如果有人可以请给我一些关于正在发生的事情的见解?

Use string.IsNullOrWhitespace()使用 string.IsNullOrWhitespace()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM