Reputation:
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
how do i remove this??
Any help will be appreciated sorry if this question is not well structured
Upvotes: 0
Views: 821
Reputation: 1608
You could use a regular textbox and just handle the KeyPressed Event. This will also prevent Copy and paste, This was taken from another post here, How do I make a textbox that only accepts numbers? .
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar)
&& !char.IsDigit(e.KeyChar)
&& e.KeyChar != '.')
{
e.Handled = true;
}
}
Upvotes: 1
Reputation: 4463
By default MaskedTextbox's PromptChar is set to "_" (underscore). Simply change its PromptChar property to " " (space)
Upvotes: 1