TextBox Space in VB By Default as padding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mahesh83
    New Member
    • Feb 2007
    • 25

    TextBox Space in VB By Default as padding

    I am New to VB

    As my Client want Spacing in the Textbox by 1 and if he press Backspace it should Keep the Cursor to that position i.e leaving one position....
    Please help me....


    Thanks & Regards
    Mahesh
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by Mahesh83
    I am New to VB

    As my Client want Spacing in the Textbox by 1 and if he press Backspace it should Keep the Cursor to that position i.e leaving one position....
    Please help me....
    Could you please try to re-phrase the question? It's just too hard to understand. (Or perhaps it's just me.)

    Comment

    • Mahesh83
      New Member
      • Feb 2007
      • 25

      #3
      Originally posted by Killer42
      Could you please try to re-phrase the question? It's just too hard to understand. (Or perhaps it's just me.)
      Thanks for Quick Response


      My question is when my data comes from database in the Textbox

      For ex.
      I had fill the dsn and showed the data on the Textbox(txtaccn o.Text)

      ............... ............... ............... ............... .....
      Dim adaname As New SqlDataAdapter( "select AccountNo from_ customers where custid = '" + cutidtext + "'", nwindconn)
      Dim dsn As New DataSet
      adaname.Fill(ds n)

      txtaccno.Text = " " + dsn.Tables(0).R ows(0)("Account No").ToString ()
      ............... ............... ............... ............... ....
      i dont know is it proper way to show space?

      Then if user wants to clear he/she will clear data i.e accountno by backspace or clear then

      But i had used Space in the Textbox that spaces is removed and user can start from zeroth position on the Textbox


      So my question is like

      1. Is it Proper Way to Show spacing in VB or another option like padding....plea se suggest

      2. If user Clears the Data from the Textbox i.e AccountNo. cursor comes to Zeorth Position ...is there any option that cursor showed start at the First or Second Position by default for each Textboxes i have

      Thanks & Regards
      Mahesh

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I suppose one option would be to have some code in the Change event for the textbox, which says something like
        Code:
        If Text1.Text = "" Then
          Text1.Text = " "
        End If
        However, there's a danger that making a change to the textbox contents while processing the change event could produce an infinite loop. What I usually do in such a case is create a static variable to prevent recursion. For example...
        Code:
        Static Busy As Boolean
        If Not Busy Then
          Busy = True
          If Text1.Text = "" Then
            Text1.Text = " "
          End If
          Busy=False
        End If

        Comment

        • Mahesh83
          New Member
          • Feb 2007
          • 25

          #5
          At which event should i paste that Code....

          For exmaple:

          i put that code in the TextChanged event it worked..... but if user wants to insert new data in it he may clear the Textbox and he may use Backspace, or Clear Button .....
          so in this case cursor goes to zeorth position and starts data inserting in it....

          my question is.......
          It should take that Space and should start from the spacing given?

          Thanks And Regards
          Mahesh

          Comment

          • Mahesh83
            New Member
            • Feb 2007
            • 25

            #6
            If user wants to enter text in the Textbox it goes to Zeorth Postion
            Can you Please tell if user enters text it should Start from the Space given


            Thanks and Regards
            Mahesh

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by Mahesh83
              If user wants to enter text in the Textbox it goes to Zeorth Postion
              Can you Please tell if user enters text it should Start from the Space given
              Sorry, I didn't have a chance to get into TheScripts yesterday.

              What you could do is, after setting the value to a space, add this line
              Code:
              Text1.SelStart = 1
              You could also do a check in places like the GotFocus event to ensure that the cursor doesn't go to the start of the field.

              Comment

              • Mahesh83
                New Member
                • Feb 2007
                • 25

                #8
                Originally posted by Killer42
                Sorry, I didn't have a chance to get into TheScripts yesterday.

                What you could do is, after setting the value to a space, add this line
                Code:
                Text1.SelStart = 1
                You could also do a check in places like the GotFocus event to ensure that the cursor doesn't go to the start of the field.

                Thank you its working......

                i have another query

                i have textbox for Password where i used the code for the event....its taking space but putting star for that space because for that textbox i had used passwordchar *


                this code is in my designer form

                Me.txtpassword. PasswordChar = Global.Microsof t.VisualBasic.C hrW(42)

                so to avoid that * and put space for that textbox.

                Thanks & Regards
                Mahesh

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  As far as I can see, you would have to do the whole asterisk thing yourself. Because once you set Password for a textbox control, it will use the character for everything which is displayed, including spaces.

                  Um... why do you want to show a space at the start of the password field, anyway?

                  Comment

                  • Mahesh83
                    New Member
                    • Feb 2007
                    • 25

                    #10
                    Originally posted by Killer42
                    As far as I can see, you would have to do the whole asterisk thing yourself. Because once you set Password for a textbox control, it will use the character for everything which is displayed, including spaces.

                    Um... why do you want to show a space at the start of the password field, anyway?
                    Thank you for the Help


                    Thanks & Regards
                    Mahesh

                    Comment

                    • Mahesh83
                      New Member
                      • Feb 2007
                      • 25

                      #11
                      Okay, it's Friday evening where I am and I'm tired, so for now let's try a simple brute-force approach. Create a timer, set interval really short (100, perhaps). Then paste this into the Timer event procedure...
                      Code:
                      Dim CursorPos As Long
                      With Text1  ' Change this to the name of your textbox.
                        CursorPos = .SelStart
                        If .SelLength > 0 Then Exit Sub
                        If .Text = "" Then
                          .Text = " "
                          Exit Sub
                        End If
                        If Left(.Text, 1) <> " " Then
                          .Text = .Text + 1
                          .SelStart = CursorPos + 1
                          Exit Sub
                        End If
                        If .SelStart = 1 Then 
                          .SelStart = 2
                        End If
                      End With
                      This is just straight out of my head, so may need some debugging.

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Please accept my apologies Mahesh83. I've only just become a moderator, and accidentally used the "Edit" feature instead of the "Reply". It looks as though I have overwritten your last message. I promise to be much more careful in future.

                        Comment

                        • Mahesh83
                          New Member
                          • Feb 2007
                          • 25

                          #13
                          Originally posted by Killer42
                          Please accept my apologies Mahesh83. I've only just become a moderator, and accidentally used the "Edit" feature instead of the "Reply". It looks as though I have overwritten your last message. I promise to be much more careful in future.

                          i put code in

                          Private Sub txtusername_Tex tChanged(ByVal sender As Object, ByVal e As System.EventArg s) Handles txtusername.Tex tChanged
                          'Static Busy As Boolean
                          'If Not Busy Then
                          ' Busy = True
                          ' If txtusername.Tex t = "" Then
                          ' txtusername.Tex t = " "
                          ' txtusername.Sel ectionStart = 1
                          ' End If
                          ' Busy = False
                          'End If



                          Dim CursorPos As Long
                          With txtusername ' Change this to the name of your textbox.
                          CursorPos = .SelectionStart
                          If .SelectionLengt h > 0 Then Exit Sub
                          If .Text = "" Then
                          .Text = " "
                          Exit Sub
                          End If
                          If Left(.Text, 1) <> " " Then
                          .Text = .Text + 1
                          .SelectionStart = CursorPos + 1
                          Exit Sub
                          End If
                          If .SelectionStart = 1 Then
                          .SelectionStart = 2
                          End If
                          End With
                          End Sub


                          but its givning error for public property left() as 'integer' has no parameters and its return type cannot be indexed

                          Comment

                          Working...