Search code examples
c#.nettextboxmaskingmaskedtextbox

MaskedTextBox.Mask not working properly


I am using MaskedTextBox in my code to for a date field.

When I am giving maskedTextBox1.Mask = "00/00/0000 00:00 AA" in code,on running the application in my machine it works fine and mask in the textbox appears as [_ _/_ _ _/____ __:__ _ _ _]

But when i am running the same application in another machine, the mask appears as [_ _ _-_ _ _-____ __:__ _ _ _]

How is the / replaced by -? Is the mask machine dependent, if yes how can we avoid this problem?


Solution

  • This problem can be avoided by providing escape character before '/'.
    e.x. maskedTextBox1.Mask = @"00\/00\/0000 00:00 AA";
    This will force the system to show '/' on the screen.