Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how make textbox or masked textbox take month and year only such as "mm/yyyy"

how make textbox or masked textbox take month and year only such as "mm/yyyy"

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nabawoka
    wrote on last edited by
    #1

    i can`t make it in textbox but in masked textbox i make the mask "00\0000" but user can enter month greater than 12 so i want to restrict this or make valdation type the mask follow so user can`t enter > 12 or <1 or > this year how ? :-) or can i make new type ("mm\yyyy") :confused:

    OriginalGriffO M N L 4 Replies Last reply
    0
    • N Nabawoka

      i can`t make it in textbox but in masked textbox i make the mask "00\0000" but user can enter month greater than 12 so i want to restrict this or make valdation type the mask follow so user can`t enter > 12 or <1 or > this year how ? :-) or can i make new type ("mm\yyyy") :confused:

      OriginalGriffO Online
      OriginalGriffO Online
      OriginalGriff
      wrote on last edited by
      #2

      Rather than a MaskedTextBox, why not use a DateTimePicker? That way the date is always valid, and it is obvious regardless of locale. If you can't, then you would be best to use a ValidatingType property[^]

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • N Nabawoka

        i can`t make it in textbox but in masked textbox i make the mask "00\0000" but user can enter month greater than 12 so i want to restrict this or make valdation type the mask follow so user can`t enter > 12 or <1 or > this year how ? :-) or can i make new type ("mm\yyyy") :confused:

        M Offline
        M Offline
        Manfred Rudolf Bihy
        wrote on last edited by
        #3

        Hello Mohamed, I don't know if it would fit in your scenario, but I'd advise you to try to use a datetime picker where Format property is set to custom. Cheers Manfred

        1 Reply Last reply
        0
        • N Nabawoka

          i can`t make it in textbox but in masked textbox i make the mask "00\0000" but user can enter month greater than 12 so i want to restrict this or make valdation type the mask follow so user can`t enter > 12 or <1 or > this year how ? :-) or can i make new type ("mm\yyyy") :confused:

          N Offline
          N Offline
          Nabawoka
          wrote on last edited by
          #4

          thnx to all ok .... how to create new type in C#

          1 Reply Last reply
          0
          • N Nabawoka

            i can`t make it in textbox but in masked textbox i make the mask "00\0000" but user can enter month greater than 12 so i want to restrict this or make valdation type the mask follow so user can`t enter > 12 or <1 or > this year how ? :-) or can i make new type ("mm\yyyy") :confused:

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            The maskedtextbox is described here[^], and it's usage is explained with a nice example at the bottom of that page. You'd set the mask to "00/0000" according the example, but I bet that it takes somewhat more customizing than merely changing the mask.

            Mohamed Nabawy wrote:

            can i make new type ("mm\yyyy")

            You could create a new class that encapsulates both a month and a year. The current edit-controls would not know how to interact with your class, unless you also create a TypeConverter. I suggest you keep it simple and put two textboxes on that form; limit the keys that can be entered to numbers. Done :)

            I are Troll :suss:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups