0

I asked how to format a Textbox to accept only numbers but was adviced to use a Masked Textbox and set the Mask Property but doing this i have encountered some Problems

1) The masked textbox requires a maximum number of data a user can type to be set, but i want the user to be able to enter unlimited data

2) The masked textbox shows an Underscore

Underscore

how do i remove this??

Any help will be appreciated sorry if this question is not well structured

4

2 回答 2

1

默认情况下,MaskedTextbox 的PromptChar设置为“_”(下划线)。只需将其 PromptChar 属性更改为“”(空格)

于 2013-07-08T23:19:31.020 回答
1

您可以使用常规文本框并只处理 KeyPressed 事件。这也将防止复制和粘贴,这是取自这里的另一篇文章, 如何制作一个只接受数字的文本框? .

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) 
        && !char.IsDigit(e.KeyChar) 
        && e.KeyChar != '.')
    {
        e.Handled = true;
    }
}
于 2013-07-08T23:25:01.523 回答