Help on C# MaskedTextBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • navanova
    New Member
    • Feb 2007
    • 30

    Help on C# MaskedTextBox

    Hi Guys, the masked text box in my C# application has a customed format as >LLL/LL/LL/000/0/0000/0000. When the application loads it will be like ( / / /
    / / / ). The user can insert any characters in the first 7 blank spaces (in the place of L's) and it will allow any numbers in the remaining 12 blank
    spaces (in the place of 0's). When the user finishes inserting, the masked text box displays something like ABC/DE/FGH/012/3/4567/8900.

    However i want to make a restriction on the first 3 characters(ABC) . I want the application to insert the first 3 charactes (i.e ABC to be some other pre-defined character, say CHW and the user is expected to fill the remaining.)
    Can anybody help me on this?

    Thanks,
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    The small amount I've done with masked text boxes is for times. Limiting to "24:00" for example.

    I've always just set the text property of the box when the program starts and reads the saved value.

    Have you tried just setting the text of the box to "CMW" and letting the user take it from there?

    Comment

    • navanova
      New Member
      • Feb 2007
      • 30

      #3
      Originally posted by tlhintoq
      The small amount I've done with masked text boxes is for times. Limiting to "24:00" for example.

      I've always just set the text property of the box when the program starts and reads the saved value.

      Have you tried just setting the text of the box to "CMW" and letting the user take it from there?
      What I want is, the application that i've developed will be used by a number of users. the first three letters of the masked text box shows the code of the user. The application gets the code of the user when the user first logs in (From Username & Password). Thus, once the system recognizes the specific user, it will insert the user code on the first part of the masked text box. Therefore, the user is not asked to insert his/her code every time they logs in.What I want to do is this.

      If this is not clear, i'm more than happy to elaborate it again.

      Thanks,

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Originally posted by navanova
        What I want is, the application that i've developed will be used by a number of users. the first three letters of the masked text box shows the code of the user. The application gets the code of the user when the user first logs in (From Username & Password). Thus, once the system recognizes the specific user, it will insert the user code on the first part of the masked text box. Therefore, the user is not asked to insert his/her code every time they logs in.What I want to do is this.

        If this is not clear, i'm more than happy to elaborate it again.

        Thanks,
        That makes sense. And sounds like what I described. For me, when I read the shutdown time property I stick it in the masked text box's .Text property. You'll do the same when you read/receive/calculate the user code based on their Username and Password.

        If your Username is "ClintXYZ" and your code is the last three letters of the username then after you get the user to log in set the text of the maskedtextbox, something like this...

        myMaskedTextBox .Text = szUsername.subs tring(szUsernam e.length-4,3);

        The reason for the -4 is because the string itself is zero-based, so for the X which is the 6th character it is in position 5 of the string.

        How you calculate your 3 digit code is up to you. This is just for concept.

        Another approach would be to not worry about putting the usercode into the text box. After all, do you really need to? You already know what the usercode is. So let the user input everything else, then combine the known usercode to the userinput before you do something with it.

        Comment

        Working...