enter key press

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

    #1

    enter key press

    Hi,


    I want my user to be able to rename a button control by selcting rename



    from a menu. This then opens a text box in which to enter the new name
    in. I want the button control to inherit the name when the enter key is



    pressed.


    Below is my code so far....all I am missing is the code to accept the
    changes on hitting enter. I have tried various things but cannot get it



    working. I really want to control everything from within this private
    sub.


    Any ideas?


    Private Sub RenameToolStrip MenuItem_Click( ByVal sender As
    System.Object, ByVal e As System.EventArg s) Handles
    RenameToolStrip MenuItem.Click
    Dim NewTxtBox As New TextBox
    NewTxtBox.Locat ion = ActiveControl.L ocation
    Me.Controls.Add (NewTxtBox)
    NewTxtBox.Bring ToFront()
    NewTxtBox.Text = "Type and Hit Enter"
    ActiveControl.T ext = NewTxtBox.Text
    End If
    End Sub


    Reply »

  • Ryan S. Thiele

    #2
    Re: enter key press

    Try using an input control. It's built into MSVB

    I'll use some of your code...

    Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
    Dim s As String = InputBox("Enter a new name", "Rename control")
    If s <"" Then
    MyButton.Name = s
    End If
    End Sub

    If you want to try another way let me know! Good luck.
    Ryan
    --
    --
    Thiele Enterprises - The Power Is In Your Hands Now!
    --
    "Marc" <marc_crosby@ho tmail.comwrote in message
    news:1165069824 .944957.196720@ 79g2000cws.goog legroups.com...
    Hi,


    I want my user to be able to rename a button control by selcting rename



    from a menu. This then opens a text box in which to enter the new name
    in. I want the button control to inherit the name when the enter key is



    pressed.


    Below is my code so far....all I am missing is the code to accept the
    changes on hitting enter. I have tried various things but cannot get it



    working. I really want to control everything from within this private
    sub.


    Any ideas?


    Private Sub RenameToolStrip MenuItem_Click( ByVal sender As
    System.Object, ByVal e As System.EventArg s) Handles
    RenameToolStrip MenuItem.Click
    Dim NewTxtBox As New TextBox
    NewTxtBox.Locat ion = ActiveControl.L ocation
    Me.Controls.Add (NewTxtBox)
    NewTxtBox.Bring ToFront()
    NewTxtBox.Text = "Type and Hit Enter"
    ActiveControl.T ext = NewTxtBox.Text
    End If
    End Sub


    Reply »


    Comment

    • Marc

      #3
      Re: enter key press

      thanks,

      actaully thre part i am struggling with is how to hit enter to accept
      the changes?


      Ryan S. Thiele wrote:
      Try using an input control. It's built into MSVB
      >
      I'll use some of your code...
      >
      Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
      ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
      Dim s As String = InputBox("Enter a new name", "Rename control")
      If s <"" Then
      MyButton.Name = s
      End If
      End Sub
      >
      If you want to try another way let me know! Good luck.
      Ryan
      --
      --
      Thiele Enterprises - The Power Is In Your Hands Now!
      --
      "Marc" <marc_crosby@ho tmail.comwrote in message
      news:1165069824 .944957.196720@ 79g2000cws.goog legroups.com...
      Hi,
      >
      >
      I want my user to be able to rename a button control by selcting rename
      >
      >
      >
      from a menu. This then opens a text box in which to enter the new name
      in. I want the button control to inherit the name when the enter key is
      >
      >
      >
      pressed.
      >
      >
      Below is my code so far....all I am missing is the code to accept the
      changes on hitting enter. I have tried various things but cannot get it
      >
      >
      >
      working. I really want to control everything from within this private
      sub.
      >
      >
      Any ideas?
      >
      >
      Private Sub RenameToolStrip MenuItem_Click( ByVal sender As
      System.Object, ByVal e As System.EventArg s) Handles
      RenameToolStrip MenuItem.Click
      Dim NewTxtBox As New TextBox
      NewTxtBox.Locat ion = ActiveControl.L ocation
      Me.Controls.Add (NewTxtBox)
      NewTxtBox.Bring ToFront()
      NewTxtBox.Text = "Type and Hit Enter"
      ActiveControl.T ext = NewTxtBox.Text
      End If
      End Sub


      Reply »

      Comment

      • Ryan S. Thiele

        #4
        Re: enter key press

        well, you will have to go outside of your sub. You have to add handlers for
        your textbox.

        Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
        ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
        Dim NewTxtBox As New TextBox
        NewTxtBox.Locat ion = ActiveControl.L ocation

        'Added code
        AddHandler NewTxtBox, AddessOf TxtBickClickEve nt

        Me.Controls.Add (NewTxtBox)
        NewTxtBox.Bring ToFront()
        NewTxtBox.Text = "Type and Hit Enter"
        ActiveControl.T ext = NewTxtBox.Text
        End Sub

        Private sub TxtBickClickEve nt(Sender as object, e as System.Eventarg s)
        'Processing from the enter key
        End Sub


        I would take this approach....

        -----

        Public Class AClass

        Comment

        • Marc

          #5
          Re: enter key press

          great!

          i shall try that
          Ryan S. Thiele wrote:
          well, you will have to go outside of your sub. You have to add handlers for
          your textbox.
          >
          Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
          ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
          Dim NewTxtBox As New TextBox
          NewTxtBox.Locat ion = ActiveControl.L ocation
          >
          'Added code
          AddHandler NewTxtBox, AddessOf TxtBickClickEve nt
          >
          Me.Controls.Add (NewTxtBox)
          NewTxtBox.Bring ToFront()
          NewTxtBox.Text = "Type and Hit Enter"
          ActiveControl.T ext = NewTxtBox.Text
          End Sub
          >
          Private sub TxtBickClickEve nt(Sender as object, e as System.Eventarg s)
          'Processing from the enter key
          End Sub
          >
          >
          I would take this approach....
          >
          -----
          >
          Public Class AClass
          .
          .
          'Declare the Generic TextBox in the class...
          Private WithEvents RenameTextBox as new TextBox
          >
          'A Variable that will hold the Name
          dim CName as string = ""
          >
          'A sub for the clickevent
          Private sub RenameTextBox_C lick(Sender as object, e as System.Eventarg s)
          Handles RenameTextBox.C lick
          'Processing from the enter key
          CName = RenameTextBox.T ext
          End Sub
          >
          'Now your code...
          Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
          ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
          RenameTextBox = new TextBox
          RenameTextBox.L ocation = ActiveControl.L ocation
          >
          'Added code
          AddHandler NewTxtBox, AddessOf TxtBickClickEve nt
          >
          Me.Controls.Add (RenameTextBox)
          NewTxtBox.Bring ToFront()
          NewTxtBox.Text = "Type and Hit Enter"
          >
          'When the user clicks enter.. it will rise the RenameTextBox_C lick
          event
          >
          ActiveControl.T ext = CName
          End Sub
          End Class
          >
          Give this a try, it's a little lengthy, but it should work.
          -----
          >
          --
          --
          Thiele Enterprises - The Power Is In Your Hands Now!
          --
          "Marc" <marc_crosby@ho tmail.comwrote in message
          news:1165072683 .481726.110970@ j44g2000cwa.goo glegroups.com.. .
          thanks,
          >
          actaully thre part i am struggling with is how to hit enter to accept
          the changes?
          >
          >
          Ryan S. Thiele wrote:
          Try using an input control. It's built into MSVB

          I'll use some of your code...

          Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
          ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
          Dim s As String = InputBox("Enter a new name", "Rename control")
          If s <"" Then
          MyButton.Name = s
          End If
          End Sub

          If you want to try another way let me know! Good luck.
          Ryan
          --
          --
          Thiele Enterprises - The Power Is In Your Hands Now!
          --
          "Marc" <marc_crosby@ho tmail.comwrote in message
          news:1165069824 .944957.196720@ 79g2000cws.goog legroups.com...
          Hi,


          I want my user to be able to rename a button control by selcting rename



          from a menu. This then opens a text box in which to enter the new name
          in. I want the button control to inherit the name when the enter key is



          pressed.


          Below is my code so far....all I am missing is the code to accept the
          changes on hitting enter. I have tried various things but cannot get it



          working. I really want to control everything from within this private
          sub.


          Any ideas?


          Private Sub RenameToolStrip MenuItem_Click( ByVal sender As
          System.Object, ByVal e As System.EventArg s) Handles
          RenameToolStrip MenuItem.Click
          Dim NewTxtBox As New TextBox
          NewTxtBox.Locat ion = ActiveControl.L ocation
          Me.Controls.Add (NewTxtBox)
          NewTxtBox.Bring ToFront()
          NewTxtBox.Text = "Type and Hit Enter"
          ActiveControl.T ext = NewTxtBox.Text
          End If
          End Sub


          Reply »

          Comment

          • Marc

            #6
            Re: enter key press

            Hi,

            The code below works fine....however i am trying to find a way of
            renaming the active button control with the text entered in the
            'newtxtbox' ,instead of opening a message box! -see MsgBox("test
            message") when enter is clicked).

            any ideas?

            -----------------------------------------------------------------------------------

            Private Sub RenameToolStrip MenuItem_Click( ByVal sender As
            System.Object, ByVal e As System.EventArg s) Handles
            RenameToolStrip MenuItem.Click
            Dim NewTxtBox As New TextBox
            NewTxtBox.Locat ion = ContextMenuStri p1.SourceContro l.Location
            Me.Controls.Add (NewTxtBox)
            NewTxtBox.Bring ToFront()
            NewTxtBox.Text = "Type and Hit Enter"
            AddHandler NewTxtBox.KeyPr ess, AddressOf TextBox1_KeyPre ss
            End Sub

            ---------------------------------------------------------------------------------------------------------------------------------

            Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As
            System.Windows. Forms.KeyPressE ventArgs)
            If e.KeyChar = Chr(Keys.Enter) Then
            MsgBox("test message")
            End If
            End Sub
            Marc wrote:
            great!
            >
            i shall try that
            Ryan S. Thiele wrote:
            well, you will have to go outside of your sub. You have to add handlersfor
            your textbox.

            Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
            ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
            Dim NewTxtBox As New TextBox
            NewTxtBox.Locat ion = ActiveControl.L ocation

            'Added code
            AddHandler NewTxtBox, AddessOf TxtBickClickEve nt

            Me.Controls.Add (NewTxtBox)
            NewTxtBox.Bring ToFront()
            NewTxtBox.Text = "Type and Hit Enter"
            ActiveControl.T ext = NewTxtBox.Text
            End Sub

            Private sub TxtBickClickEve nt(Sender as object, e as System.Eventarg s)
            'Processing from the enter key
            End Sub


            I would take this approach....

            -----

            Public Class AClass
            .
            .
            'Declare the Generic TextBox in the class...
            Private WithEvents RenameTextBox as new TextBox

            'A Variable that will hold the Name
            dim CName as string = ""

            'A sub for the clickevent
            Private sub RenameTextBox_C lick(Sender as object, e as System.Eventarg s)
            Handles RenameTextBox.C lick
            'Processing from the enter key
            CName = RenameTextBox.T ext
            End Sub

            'Now your code...
            Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
            ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
            RenameTextBox = new TextBox
            RenameTextBox.L ocation = ActiveControl.L ocation

            'Added code
            AddHandler NewTxtBox, AddessOf TxtBickClickEve nt

            Me.Controls.Add (RenameTextBox)
            NewTxtBox.Bring ToFront()
            NewTxtBox.Text = "Type and Hit Enter"

            'When the user clicks enter.. it will rise the RenameTextBox_C lick
            event

            ActiveControl.T ext = CName
            End Sub
            End Class

            Give this a try, it's a little lengthy, but it should work.
            -----

            --
            --
            Thiele Enterprises - The Power Is In Your Hands Now!
            --
            "Marc" <marc_crosby@ho tmail.comwrote in message
            news:1165072683 .481726.110970@ j44g2000cwa.goo glegroups.com.. .
            thanks,

            actaully thre part i am struggling with is how to hit enter to accept
            the changes?


            Ryan S. Thiele wrote:
            Try using an input control. It's built into MSVB
            >
            I'll use some of your code...
            >
            Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
            ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
            Dim s As String = InputBox("Enter a new name", "Rename control")
            If s <"" Then
            MyButton.Name = s
            End If
            End Sub
            >
            If you want to try another way let me know! Good luck.
            Ryan
            --
            --
            Thiele Enterprises - The Power Is In Your Hands Now!
            --
            "Marc" <marc_crosby@ho tmail.comwrote in message
            news:1165069824 .944957.196720@ 79g2000cws.goog legroups.com...
            Hi,
            >
            >
            I want my user to be able to rename a button control by selcting rename
            >
            >
            >
            from a menu. This then opens a text box in which to enter the new name
            in. I want the button control to inherit the name when the enter key is
            >
            >
            >
            pressed.
            >
            >
            Below is my code so far....all I am missing is the code to accept the
            changes on hitting enter. I have tried various things but cannot get it
            >
            >
            >
            working. I really want to control everything from within this private
            sub.
            >
            >
            Any ideas?
            >
            >
            Private Sub RenameToolStrip MenuItem_Click( ByVal sender As
            System.Object, ByVal e As System.EventArg s) Handles
            RenameToolStrip MenuItem.Click
            Dim NewTxtBox As New TextBox
            NewTxtBox.Locat ion = ActiveControl.L ocation
            Me.Controls.Add (NewTxtBox)
            NewTxtBox.Bring ToFront()
            NewTxtBox.Text = "Type and Hit Enter"
            ActiveControl.T ext = NewTxtBox.Text
            End If
            End Sub
            >
            >
            Reply »

            Comment

            • Ryan S. Thiele

              #7
              Re: enter key press

              Place a holder in the class.
              Dim MyActiveButton as Button

              I would place 2 sub to control the activeness of the control.

              Private Sub Buttons_MouseEn ter(ByVal sender As Object, ByVal e As
              System.EventArg s) Handles MyButton.MouseE nter 'Add more if needed
              MyActiveButton = DirectCast(Send er,Button)
              End Sub

              Private Sub Buttons_MouseLe ave(ByVal sender As Object, ByVal e As
              System.EventArg s) Handles MyButton.MouseL eave 'Add more if needed
              MyActiveButton = Nothing
              End Sub
              ----------------------------------------------------------------------------------

              Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
              ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
              Dim NewTxtBox As New TextBox
              NewTxtBox.Locat ion = ContextMenuStri p1.SourceContro l.Location
              Me.Controls.Add (NewTxtBox)
              NewTxtBox.Bring ToFront()
              NewTxtBox.Text = "Type and Hit Enter"
              AddHandler NewTxtBox.KeyPr ess, AddressOf TextBox1_KeyPre ss
              End Sub

              ---------------------------------------------------------------------------------------------------------------------------------

              Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As
              System.Windows. Forms.KeyPressE ventArgs)
              If e.KeyChar = Chr(Keys.Enter) Then
              If not (MyActiveButton is Nothing) then
              MyActiveButton = Name
              End If
              End If
              End Sub

              ---------------

              See if this works, I have tested it and it worked on my end.
              Good Luck!
              Ryan


              Comment

              • Mudhead

                #8
                Re: enter key press

                Marc,

                Why aren't you using the MenuStrips built in textbox? It only took me one
                line of code to do what you want to do.


                "Ryan S. Thiele" <maligui@verizo n.netwrote in message
                news:Vgjch.247$ bW2.220@trndny0 4...
                Place a holder in the class.
                Dim MyActiveButton as Button
                >
                I would place 2 sub to control the activeness of the control.
                >
                Private Sub Buttons_MouseEn ter(ByVal sender As Object, ByVal e As
                System.EventArg s) Handles MyButton.MouseE nter 'Add more if needed
                MyActiveButton = DirectCast(Send er,Button)
                End Sub
                >
                Private Sub Buttons_MouseLe ave(ByVal sender As Object, ByVal e As
                System.EventArg s) Handles MyButton.MouseL eave 'Add more if needed
                MyActiveButton = Nothing
                End Sub
                ----------------------------------------------------------------------------------
                >
                Private Sub RenameToolStrip MenuItem_Click( ByVal sender As System.Object,
                ByVal e As System.EventArg s) Handles RenameToolStrip MenuItem.Click
                Dim NewTxtBox As New TextBox
                NewTxtBox.Locat ion = ContextMenuStri p1.SourceContro l.Location
                Me.Controls.Add (NewTxtBox)
                NewTxtBox.Bring ToFront()
                NewTxtBox.Text = "Type and Hit Enter"
                AddHandler NewTxtBox.KeyPr ess, AddressOf TextBox1_KeyPre ss
                End Sub
                >
                ---------------------------------------------------------------------------------------------------------------------------------
                >
                Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As
                System.Windows. Forms.KeyPressE ventArgs)
                If e.KeyChar = Chr(Keys.Enter) Then
                If not (MyActiveButton is Nothing) then
                MyActiveButton = Name
                End If
                End If
                End Sub
                >
                ---------------
                >
                See if this works, I have tested it and it worked on my end.
                Good Luck!
                Ryan
                >
                >

                Comment

                Working...