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. MaskedTextBox Focus ?

MaskedTextBox Focus ?

Scheduled Pinned Locked Moved C#
question
7 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.
  • I Offline
    I Offline
    ibrahimayhans
    wrote on last edited by
    #1

    Hi, I am developing applications on C # WinForm Using MaskedTextBox and Mask Structure (999) 000 00 00 I use Only when the user clicks with the mouse, it focuses on the pressed point This Data Entry Is Incorrect and Incomplete MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning I look forward to helping you in this regard Best Regards...

    OriginalGriffO L A 3 Replies Last reply
    0
    • I ibrahimayhans

      Hi, I am developing applications on C # WinForm Using MaskedTextBox and Mask Structure (999) 000 00 00 I use Only when the user clicks with the mouse, it focuses on the pressed point This Data Entry Is Incorrect and Incomplete MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning I look forward to helping you in this regard Best Regards...

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

      I'm sorry, but that makes no sense at all to me. Perhaps an example would help?

      Sent from my Amstrad PC 1640 Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "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

      I 1 Reply Last reply
      0
      • I ibrahimayhans

        Hi, I am developing applications on C # WinForm Using MaskedTextBox and Mask Structure (999) 000 00 00 I use Only when the user clicks with the mouse, it focuses on the pressed point This Data Entry Is Incorrect and Incomplete MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning I look forward to helping you in this regard Best Regards...

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

        ibrahimayhans wrote:

        Only when the user clicks with the mouse, it focuses on the pressed point This Data Entry Is Incorrect and Incomplete

        Your perception is incorrect. The described behaviour is default in Windows, and Windows apps should adhere to the standard.

        ibrahimayhans wrote:

        MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning

        If you tab into it, you are at the beginning.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        I 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          I'm sorry, but that makes no sense at all to me. Perhaps an example would help?

          Sent from my Amstrad PC 1640 Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          I Offline
          I Offline
          ibrahimayhans
          wrote on last edited by
          #4

          But a Right Situation and a Problem When I'm Clicked and Moved to the Mouse How Can I Trigger the Home Key? SendKeys.Send("{HOME}"); It does not seem like it

          1 Reply Last reply
          0
          • L Lost User

            ibrahimayhans wrote:

            Only when the user clicks with the mouse, it focuses on the pressed point This Data Entry Is Incorrect and Incomplete

            Your perception is incorrect. The described behaviour is default in Windows, and Windows apps should adhere to the standard.

            ibrahimayhans wrote:

            MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning

            If you tab into it, you are at the beginning.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            I Offline
            I Offline
            ibrahimayhans
            wrote on last edited by
            #5

            I'm Into Content With TAB Only User Uses Mouse Sometimes There are such Problems when you click

            L 1 Reply Last reply
            0
            • I ibrahimayhans

              I'm Into Content With TAB Only User Uses Mouse Sometimes There are such Problems when you click

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

              ibrahimayhans wrote:

              Only User Uses Mouse Sometimes There are such Problems when you click

              It is not a problem, it is how it is supposed to work. When activating a control with the mouse, the cursor does not go to the start but where you select. All controls work like that. Making it work differently means unexpected behaviour. Also, someone doing data-entry does not move to the next control using the mouse, it would make for very inefficient data-entry.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              1 Reply Last reply
              0
              • I ibrahimayhans

                Hi, I am developing applications on C # WinForm Using MaskedTextBox and Mask Structure (999) 000 00 00 I use Only when the user clicks with the mouse, it focuses on the pressed point This Data Entry Is Incorrect and Incomplete MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning I look forward to helping you in this regard Best Regards...

                A Offline
                A Offline
                Alan N
                wrote on last edited by
                #7

                I think you are asking how to move the textbox caret to position 0 when the empty textbox is clicked. The first part is to get the empty state of the maskedtextbox before any data has been entered. At that point the Text property value is not String.Empty but a representation of the mask. This 'empty' text can be obtained by capturing the Text when the MaskChanged event fires. For your example it is

                "( ) "

                The second part is picking a suitable place to move the caret. When an unfocussed textbox is clicked the sequence of Enter, GotFocus and Click events occur. You'll find that attempting to set the caret position in either the Enter or GotFocus events will fail and changes must be made in the Click event handler. Combining that information gives some prototype code

                private String emptyText;

                private void MaskedTextBox_MaskChanged(object sender, EventArgs e) {
                // Capture the empty text
                MaskedTextBox mtbx = (MaskedTextBox)sender;
                emptyText = mtbx.Text;
                }

                private void MaskedTextBox_Click(object sender, EventArgs e) {
                MaskedTextBox mtbx = (MaskedTextBox)sender;
                String currentText = mtbx.Text;
                if (currentText == emptyText) {
                // Move the caret to the start of the line
                mtbx.Select(0, 0);
                }
                }

                EDIT : Correct operation of this code requires that the MaskChanged event handler is attached before the Mask is set. Alan.

                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