Home All Groups Group Topic Archive Search About
Author
2 Dec 2006 2:30 PM
Marc
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 RenameToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RenameToolStripMenuItem.Click
        Dim NewTxtBox As New TextBox
        NewTxtBox.Location = ActiveControl.Location
        Me.Controls.Add(NewTxtBox)
        NewTxtBox.BringToFront()
        NewTxtBox.Text = "Type and Hit Enter"
        ActiveControl.Text = NewTxtBox.Text
        End If
    End Sub


Reply »

Author
2 Dec 2006 3:03 PM
Ryan S. Thiele
Try using an input control. It's built into MSVB

I'll use some of your code...

Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.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_cro***@hotmail.com> wrote in message
news:1165069824.944957.196720@79g2000cws.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RenameToolStripMenuItem.Click
        Dim NewTxtBox As New TextBox
        NewTxtBox.Location = ActiveControl.Location
        Me.Controls.Add(NewTxtBox)
        NewTxtBox.BringToFront()
        NewTxtBox.Text = "Type and Hit Enter"
        ActiveControl.Text = NewTxtBox.Text
        End If
    End Sub


Reply »
Author
2 Dec 2006 3:18 PM
Marc
thanks,

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


Ryan S. Thiele wrote:
Show quoteHide quote
> Try using an input control. It's built into MSVB
>
> I'll use some of your code...
>
>  Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.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_cro***@hotmail.com> wrote in message
> news:1165069824.944957.196720@79g2000cws.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> RenameToolStripMenuItem.Click
>         Dim NewTxtBox As New TextBox
>         NewTxtBox.Location = ActiveControl.Location
>         Me.Controls.Add(NewTxtBox)
>         NewTxtBox.BringToFront()
>         NewTxtBox.Text = "Type and Hit Enter"
>         ActiveControl.Text = NewTxtBox.Text
>         End If
>     End Sub
>
>
> Reply »
Author
2 Dec 2006 3:31 PM
Ryan S. Thiele
well, you will have to go outside of your sub. You have to add handlers for
your textbox.

Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
        Dim NewTxtBox As New TextBox
        NewTxtBox.Location = ActiveControl.Location

        'Added code
        AddHandler NewTxtBox, AddessOf TxtBickClickEvent

        Me.Controls.Add(NewTxtBox)
        NewTxtBox.BringToFront()
        NewTxtBox.Text = "Type and Hit Enter"
        ActiveControl.Text = NewTxtBox.Text
End Sub

Private sub TxtBickClickEvent(Sender as object, e as System.Eventargs)
     '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_Click(Sender as object, e as System.Eventargs)
Handles RenameTextBox.Click
        'Processing from the enter key
        CName = RenameTextBox.Text
    End Sub

    'Now your code...
    Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
        RenameTextBox = new TextBox
        RenameTextBox.Location = ActiveControl.Location

        'Added code
        AddHandler NewTxtBox, AddessOf TxtBickClickEvent

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

        'When the user clicks enter.. it will rise the RenameTextBox_Click
event

        ActiveControl.Text = 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_cro***@hotmail.com> wrote in message
news:1165072683.481726.110970@j44g2000cwa.googlegroups.com...
thanks,

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


Ryan S. Thiele wrote:
Show quoteHide quote
> Try using an input control. It's built into MSVB
>
> I'll use some of your code...
>
>  Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.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_cro***@hotmail.com> wrote in message
> news:1165069824.944957.196720@79g2000cws.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> RenameToolStripMenuItem.Click
>         Dim NewTxtBox As New TextBox
>         NewTxtBox.Location = ActiveControl.Location
>         Me.Controls.Add(NewTxtBox)
>         NewTxtBox.BringToFront()
>         NewTxtBox.Text = "Type and Hit Enter"
>         ActiveControl.Text = NewTxtBox.Text
>         End If
>     End Sub
>
>
> Reply »
Author
2 Dec 2006 4:22 PM
Marc
great!

i shall try that
Ryan S. Thiele wrote:
Show quoteHide quote
> well, you will have to go outside of your sub. You have to add handlers for
> your textbox.
>
> Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
>         Dim NewTxtBox As New TextBox
>         NewTxtBox.Location = ActiveControl.Location
>
>         'Added code
>         AddHandler NewTxtBox, AddessOf TxtBickClickEvent
>
>         Me.Controls.Add(NewTxtBox)
>         NewTxtBox.BringToFront()
>         NewTxtBox.Text = "Type and Hit Enter"
>         ActiveControl.Text = NewTxtBox.Text
> End Sub
>
> Private sub TxtBickClickEvent(Sender as object, e as System.Eventargs)
>      '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_Click(Sender as object, e as System.Eventargs)
> Handles RenameTextBox.Click
>         'Processing from the enter key
>         CName = RenameTextBox.Text
>     End Sub
>
>     'Now your code...
>     Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
>         RenameTextBox = new TextBox
>         RenameTextBox.Location = ActiveControl.Location
>
>         'Added code
>         AddHandler NewTxtBox, AddessOf TxtBickClickEvent
>
>         Me.Controls.Add(RenameTextBox)
>         NewTxtBox.BringToFront()
>         NewTxtBox.Text = "Type and Hit Enter"
>
>         'When the user clicks enter.. it will rise the RenameTextBox_Click
> event
>
>         ActiveControl.Text = 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_cro***@hotmail.com> wrote in message
> news:1165072683.481726.110970@j44g2000cwa.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> > ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.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_cro***@hotmail.com> wrote in message
> > news:1165069824.944957.196720@79g2000cws.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As
> > System.Object, ByVal e As System.EventArgs) Handles
> > RenameToolStripMenuItem.Click
> >         Dim NewTxtBox As New TextBox
> >         NewTxtBox.Location = ActiveControl.Location
> >         Me.Controls.Add(NewTxtBox)
> >         NewTxtBox.BringToFront()
> >         NewTxtBox.Text = "Type and Hit Enter"
> >         ActiveControl.Text = NewTxtBox.Text
> >         End If
> >     End Sub
> >
> >
> > Reply »
Author
2 Dec 2006 5:22 PM
Marc
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 RenameToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RenameToolStripMenuItem.Click
        Dim NewTxtBox As New TextBox
        NewTxtBox.Location = ContextMenuStrip1.SourceControl.Location
        Me.Controls.Add(NewTxtBox)
        NewTxtBox.BringToFront()
        NewTxtBox.Text = "Type and Hit Enter"
        AddHandler NewTxtBox.KeyPress, AddressOf TextBox1_KeyPress
      End Sub

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

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)
        If e.KeyChar = Chr(Keys.Enter) Then
            MsgBox("test message")
        End If
    End Sub
Marc wrote:
Show quoteHide quote
> 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 RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> > ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
> >         Dim NewTxtBox As New TextBox
> >         NewTxtBox.Location = ActiveControl.Location
> >
> >         'Added code
> >         AddHandler NewTxtBox, AddessOf TxtBickClickEvent
> >
> >         Me.Controls.Add(NewTxtBox)
> >         NewTxtBox.BringToFront()
> >         NewTxtBox.Text = "Type and Hit Enter"
> >         ActiveControl.Text = NewTxtBox.Text
> > End Sub
> >
> > Private sub TxtBickClickEvent(Sender as object, e as System.Eventargs)
> >      '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_Click(Sender as object, e as System.Eventargs)
> > Handles RenameTextBox.Click
> >         'Processing from the enter key
> >         CName = RenameTextBox.Text
> >     End Sub
> >
> >     'Now your code...
> >     Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> > ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
> >         RenameTextBox = new TextBox
> >         RenameTextBox.Location = ActiveControl.Location
> >
> >         'Added code
> >         AddHandler NewTxtBox, AddessOf TxtBickClickEvent
> >
> >         Me.Controls.Add(RenameTextBox)
> >         NewTxtBox.BringToFront()
> >         NewTxtBox.Text = "Type and Hit Enter"
> >
> >         'When the user clicks enter.. it will rise the RenameTextBox_Click
> > event
> >
> >         ActiveControl.Text = 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_cro***@hotmail.com> wrote in message
> > news:1165072683.481726.110970@j44g2000cwa.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> > > ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.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_cro***@hotmail.com> wrote in message
> > > news:1165069824.944957.196720@79g2000cws.googlegroups.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 RenameToolStripMenuItem_Click(ByVal sender As
> > > System.Object, ByVal e As System.EventArgs) Handles
> > > RenameToolStripMenuItem.Click
> > >         Dim NewTxtBox As New TextBox
> > >         NewTxtBox.Location = ActiveControl.Location
> > >         Me.Controls.Add(NewTxtBox)
> > >         NewTxtBox.BringToFront()
> > >         NewTxtBox.Text = "Type and Hit Enter"
> > >         ActiveControl.Text = NewTxtBox.Text
> > >         End If
> > >     End Sub
> > >
> > >
> > > Reply »
Author
2 Dec 2006 6:06 PM
Ryan S. Thiele
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_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyButton.MouseEnter  'Add more if needed
    MyActiveButton = DirectCast(Sender,Button)
End Sub

Private Sub Buttons_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyButton.MouseLeave  'Add more if needed
    MyActiveButton = Nothing
End Sub
----------------------------------------------------------------------------------

Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
        Dim NewTxtBox As New TextBox
        NewTxtBox.Location = ContextMenuStrip1.SourceControl.Location
        Me.Controls.Add(NewTxtBox)
        NewTxtBox.BringToFront()
        NewTxtBox.Text = "Type and Hit Enter"
        AddHandler NewTxtBox.KeyPress, AddressOf TextBox1_KeyPress
End Sub

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

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)
        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
Author
3 Dec 2006 4:48 PM
Mudhead
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" <mali***@verizon.net> wrote in message
news:Vgjch.247$bW2.220@trndny04...
Show quoteHide quote
> 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_MouseEnter(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyButton.MouseEnter  'Add more if needed
>    MyActiveButton = DirectCast(Sender,Button)
> End Sub
>
> Private Sub Buttons_MouseLeave(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyButton.MouseLeave  'Add more if needed
>    MyActiveButton = Nothing
> End Sub
> ----------------------------------------------------------------------------------
>
> Private Sub RenameToolStripMenuItem_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles RenameToolStripMenuItem.Click
>        Dim NewTxtBox As New TextBox
>        NewTxtBox.Location = ContextMenuStrip1.SourceControl.Location
>        Me.Controls.Add(NewTxtBox)
>        NewTxtBox.BringToFront()
>        NewTxtBox.Text = "Type and Hit Enter"
>        AddHandler NewTxtBox.KeyPress, AddressOf TextBox1_KeyPress
> End Sub
>
> ---------------------------------------------------------------------------------------------------------------------------------
>
> Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
> System.Windows.Forms.KeyPressEventArgs)
>        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
>
>