none
[how do i do this?] When you press enter in the text box and the words hello are in it, it will do a function RRS feed

All replies

  • Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
            If e.KeyCode = Keys.Enter Then
                TextBox1.Text = "Hello World"
            End If
        End Sub

    Mary

    Friday, December 1, 2017 2:53 PM
  • Like this?

    Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
        If e.KeyCode = Keys.Enter Then
            If TextBox1.Text.ToLower = "hello world" Then
                If DoSomething() Then
                    '
                Else
                    '
                End If
            End If
        End If
    End Sub
    Private Function DoSomething() As Boolean
        '
        ' do something
        '
        Return True
    End Function


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, December 1, 2017 3:03 PM
    Moderator
  • Hi

    Or perhaps like this

    ' Form1 with TextBox1 and TextBox2
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
            Dim tb As TextBox = DirectCast(sender, TextBox)
            TextBox2.Text = Nothing
            If e.KeyCode = Keys.Enter Then
                If tb.Text.ToLower.Contains("hello") Then
                    TextBox2.Text = tb.Text & SomeFunction()
                End If
            End If
        End Sub
        Function SomeFunction() As String
            Return " Welcome"
        End Function
    End Class
    


    Regards Les, Livingston, Scotland

    Friday, December 1, 2017 3:15 PM
  • Usually the form also contains a button, such as “OK” or “Apply”. Then go to Form Designer, select the form, and set the “AcceptButton” property.

    Also handle the Click event of the button, where check the text using an If.

    Pressing <Enter> in textbox will invoke the Click event of the button.

    I think that this is convenient, since you can either press <Enter> or click the familiar button. It is up to you to use this approach.

    Friday, December 1, 2017 5:03 PM
  • Title explains what I need, please reply with the code! :)

    Well is this supposed to be case sensitive for the word in the TextBox?

    It may be a good idea to create a ListOfString or DictionaryOfString/Something for comparison to word(s) typed into TextBox or some class perhaps that would be used to cause something to happen if a word or words is/are typed into a TextBox.

    However case sensitivity requirement is needed to be known as well where spell checking is required which WPF TextBox can perform but not Windows Forms TextBox. You say Hello and my Nanna use to say Halloo (over the phone) but I suppose she spelled it correctly.


    La vida loca

    Friday, December 1, 2017 5:57 PM
  • Hi CTahmid,

    As Viorel_'s said that there are many button event in the project, sometime you enter some text in the Textbox, then press enter to invoke button click event.

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            MessageBox.Show("Thanks for clicking!")
        End Sub
    
        Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
            If TextBox1.Text = "Hello Word!" Then
                If e.KeyChar = Chr(13) Then
                    Button6_Click(Me, EventArgs.Empty)
                End If
            End If
        End Sub

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 4, 2017 2:17 AM
    Moderator