我正在尝试在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;
答案 0 :(得分:1)
如果您希望它显示“40.99%”,请将您的面具更改为“00.00%”
答案 1 :(得分: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%";
}