0

我试图在 MaskedTextBox 中显示一个百分比,字符串在其“40.99”中传递,但是当它显示在表单上时,它是“409.9%”。

填充值

 if (_person.Percentage != null)
    maskedTextBoxPercentage.Text = _person.Percentage.ToString();
 else
 {
    maskedTextBoxPercentage.Text = 0.00.ToString();
 }

maskedTextBoxPercentage 属性

 this.maskedTextBoxPercentage.Location = new System.Drawing.Point(437, 125);
 this.maskedTextBoxPercentage.Mask = "000.00%";
 this.maskedTextBoxPercentage.Name = "maskedTextBoxPercentage";
 this.maskedTextBoxPercentage.Size = new System.Drawing.Size(129, 20);
 this.maskedTextBoxPercentage.TabIndex = 65;

在此处输入图像描述

4

2 回答 2

1

尝试这个 :

try
            {
                this.maskedTextBoxPercentage.Mask = "00.00%";

            }
            catch (Exception)
            {
                this.maskedTextBoxPercentage.Mask = "000%";
            }

或者你也可以试试这个:

try
        {
            this.maskedTextBoxPercentage.Mask = "00.00%";

        }
        catch (Exception)
        {
            this.maskedTextBoxPercentage.Text = "100%";
        }
于 2012-08-10T20:30:13.607 回答
1

如果您希望它显示“40.99%”,请将您的掩码更改为“00.00%”

于 2012-08-10T20:16:14.150 回答