Auto Select Upon Start

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moamin123
    New Member
    • Nov 2007
    • 14

    Auto Select Upon Start

    I have created a keyboard program, though I am having one simple problem.

    When the program starts I want "Just Type Here!" to appear on the textbox and when you click on a button I want the text to replace the "Just Type Here".

    I was thinking I could write a code so that when the program loads it selects the text and when text changes (ie. when a button is pressed and another letter appears) then the "Just Type Here" text will go.

    If someone can help me with this I will be really grateful.
    Last edited by Killer42; Nov 6 '07, 06:12 AM.
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by moamin123
    i have created a keyboard program though ...

    if someone can help me with this i will be really greatfull
    Sure, first of all try making the default text "Just type here"
    Check that the EnterFieldBehav ior is set as you wish (it's a property of the textbox). If its set "selectAll" when you enter the textbox, it'll select "Just type here" and when you type something it'll be replaced, that'll be a fast way.

    Other way is in the TextBox_KeyDown event...you could define a boolean and clear the text box if the boolean is false, also make the boolean true, so it'll clean the textbox only the first time a key is pressed.

    There're many other ways. But this should be enoug.

    HTH

    PS define the boolean outside the sub
    Last edited by kadghar; Nov 6 '07, 12:50 AM. Reason: add a PS

    Comment

    • moamin123
      New Member
      • Nov 2007
      • 14

      #3
      I am using Visual Basic and I can't find EnterFieldBehav ior in the textbox properties.
      Last edited by Killer42; Nov 6 '07, 06:13 AM.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by moamin123
        I am using Visual Basic and I can't find EnterFieldBehav ior in the textbox properties.
        I think we need to know what version of VB.
        Last edited by Killer42; Nov 6 '07, 06:14 AM.

        Comment

        • moamin123
          New Member
          • Nov 2007
          • 14

          #5
          Well, I'm using Visual Studio 2005 so it's Visual Basic 2005.
          Last edited by Killer42; Nov 6 '07, 06:14 AM.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by moamin123
            I was thinking I could write a code so that when the program loads it selects the text and when text changes (ie. when a button is pressed and another letter appears) then the "Just Type Here" text will go.
            Well, I'm not personally familiar with VB2005, but in VB6 I would put this code in the Form_Load event...
            [CODE=vb]Text1.SelStart = 1
            Text1.SelLength = 500[/CODE]The "500" can be pretty much anything, as long as it's at least the length of the text.

            The "Just Type Here" can be placed in the textbox at design time, of course. And from the sound of it, the EnterFieldBehav ior property will achieve the same thing as this code, except every time you enter the field rather than once when the form loads. However, searching the MSDN website and the web in general seems to indicate that it's only applicable in Outlook.

            Comment

            • moamin123
              New Member
              • Nov 2007
              • 14

              #7
              nope that doesnt work :(

              Comment

              • kadghar
                Recognized Expert Top Contributor
                • Apr 2007
                • 1302

                #8
                Originally posted by moamin123
                nope that doesnt work :(
                did you try the boolean??

                Dim boo1 as boolean

                And inside the Key Down event of the textbox write:

                [CODE=vb]if boo1= false then
                boo1=true
                text1.text=""
                end if[/CODE]

                That should work

                Comment

                • YarrOfDoom
                  Recognized Expert Top Contributor
                  • Aug 2007
                  • 1243

                  #9
                  As you don't use your keyboard, but buttons on your form, I would add kadghar's code at the end of the code for each clicked-event of your buttons.

                  Comment

                  • moamin123
                    New Member
                    • Nov 2007
                    • 14

                    #10
                    thanks for all your help but this is getin too complicated 4 me to understand lol

                    Comment

                    • YarrOfDoom
                      Recognized Expert Top Contributor
                      • Aug 2007
                      • 1243

                      #11
                      OK, here's an example, see if you can understand it.
                      (should be placed in Your projects folder of Visual Studio 2005)
                      Attached Files

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Originally posted by moamin123
                        nope that doesnt work :(
                        It certainly will, assuming you get the syntax right for VB2005. It's perfectly simple. When the form is loaded, select the entire text in the textbox.

                        However, I expect that when adding stuff as the buttons are clicked, you probably should be placing each character in .SelText rather than adding it onto .Text property.

                        Comment

                        • moamin123
                          New Member
                          • Nov 2007
                          • 14

                          #13
                          thank you soo much i understand wt 2 do nw :D cheers guys

                          Comment

                          Working...