简体   繁体   English

Masked TextBox无法识别10等于10

[英]Masked TextBox doesn't recognize 10 as ten

For i As Integer = 0 To mtPig.Text
        MessageBox.Show(i)
    Next

I used a MaskedTextBox with a 2-digit mask. 我使用了带有2位数字掩码的MaskedTextBox。
If I put 10, it shows 0 and 1. 如果我输入10,则显示0和1。
If I put 9, it shows 0-9. 如果我输入9,则显示0-9。

Why doesn't it read the zero next to one? 为什么它不读一旁边的零? (10) (10)
How can I make 10 read as ten? 我怎样才能使10 读为 10?
UPDATE: 更新:
在此处输入图片说明

Try this: 尝试这个:

For i As Integer = 0 To Integer.Parse(mtPig.Text)
    MessageBox.Show(i)
Next

Alright, the problem is your PrompChar:0, all 0s will be treated as prompt character and discarded from value. 好的,问题是您的PrompChar:0,所有0都将被视为提示字符并从值中丢弃。

To solve it, do either 要解决此问题,请执行任一

  • change your PromptChar to _ (underscore) 将您的PromptChar更改为_(下划线)
  • or set the MaskedTextbox property named TextMaskFormat to IncludePrompt 或将名为TextMaskFormat的MaskedTextbox属性设置为IncludePrompt

GOOG Luck!! 祝你好运!!

For loop doesn't recognize 10 as ten For循环无法将10识别为十

No, For loop does not magically transform a string to an int. 不,For循环不会神奇地将字符串转换为int。

Cast, convert, do it in code. 转换,转换并用代码完成。 But do not assume the compiler will magically do converts. 但是不要以为编译器会神奇地进行转换。

you must convert it to integer then try this...: 您必须将其转换为整数,然后尝试...:

Cint(mtPig.Text) 

or 要么

Convert.ToInt32(mtPig.Text)

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

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