|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
enter key pressI 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 » 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 I want my user to be able to rename a button control by selcting renamenews:1165069824.944957.196720@79g2000cws.googlegroups.com... Hi, 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 » 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 » 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 actaully thre part i am struggling with is how to hit enter to acceptnews:1165072683.481726.110970@j44g2000cwa.googlegroups.com... thanks, 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 » 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 » 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 » 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 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 > >
best way to learn Windows Forms
Upgrading Access 97 application to dotNet For loop variable date Merging two tables in Dataset? I only want to get the matching info based on the two key fields Working with a database How to set an objects property using Reflection How do you start an assembly dynamically with constructors Enter Key vs. Tab Key How Do I Kill Non-Printable Characters? Q: VS2005 |
|||||||||||||||||||||||