TextBox KeyPress

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordi Rico

    #1

    TextBox KeyPress

    Hi,
    I was wondering how could I do something which was really easy to do
    with VB 6.0.
    Let's suppose I have a textbox in which I want to capture some key
    events to handle them (for example a numeric only textbox). It is easy,
    with e.handled=True.
    But what if what I want to do is replacing the key I'm pressing with
    some other code? For example, catching all the vowels keys and
    replacing with "*", so when they are writing in the textbox, a message
    like "I like cats" would show like "* l*k* c*ts". I don't have access
    to replace the incoming key, so no idea of doing this...
    Thanks!

  • Robin Tucker

    #2
    Re: TextBox KeyPress


    Well, you can say that e.handled = True and then manually append the * to
    the string in the text box yourself.


    "Jordi Rico" <jordirico@gmai l.com> wrote in message
    news:1126862071 .588639.190780@ g43g2000cwa.goo glegroups.com.. .[color=blue]
    > Hi,
    > I was wondering how could I do something which was really easy to do
    > with VB 6.0.
    > Let's suppose I have a textbox in which I want to capture some key
    > events to handle them (for example a numeric only textbox). It is easy,
    > with e.handled=True.
    > But what if what I want to do is replacing the key I'm pressing with
    > some other code? For example, catching all the vowels keys and
    > replacing with "*", so when they are writing in the textbox, a message
    > like "I like cats" would show like "* l*k* c*ts". I don't have access
    > to replace the incoming key, so no idea of doing this...
    > Thanks!
    >[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: TextBox KeyPress

      "Robin Tucker" <unmailable@due tospam.com> schrieb:[color=blue]
      > Well, you can say that e.handled = True and then manually append the * to
      > the string in the text box yourself.[/color]

      \\\
      Private Sub TextBox1_KeyPre ss( _
      ByVal sender As Object, _
      ByVal e As KeyPressEventAr gs _
      ) Handles TextBox1.KeyPre ss
      Select Case e.KeyChar
      Case "a"c, "e"c, "i"c, "o"c, "u"c
      e.Handled = True
      Me.TextBox1.Sel ectedText = "*"
      End Select
      End Sub
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Phil G.

        #4
        Re: TextBox KeyPress

        Hi,

        Not sure what you mean by 'I don't have access to replace incoming key'.
        This might work for you:-

        Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As
        System.Windows. Forms.KeyPressE ventArgs) Handles TextBox1.KeyPre ss
        If e.KeyChar = "e" Then 'Add additional Boolean logic for other
        vowels
        TextBox1.Text = TextBox1.Text & "*"
        TextBox1.Select ionStart = TextBox1.Text.L ength
        e.Handled = True
        End If
        End Sub

        "Jordi Rico" <jordirico@gmai l.com> wrote in message
        news:1126862071 .588639.190780@ g43g2000cwa.goo glegroups.com.. .[color=blue]
        > Hi,
        > I was wondering how could I do something which was really easy to do
        > with VB 6.0.
        > Let's suppose I have a textbox in which I want to capture some key
        > events to handle them (for example a numeric only textbox). It is easy,
        > with e.handled=True.
        > But what if what I want to do is replacing the key I'm pressing with
        > some other code? For example, catching all the vowels keys and
        > replacing with "*", so when they are writing in the textbox, a message
        > like "I like cats" would show like "* l*k* c*ts". I don't have access
        > to replace the incoming key, so no idea of doing this...
        > Thanks!
        >[/color]


        Comment

        Working...