Hi,
I am building a really complex program, and the only thing that i cannot make work right is the menu.
The menu is basicaly 13 textboxes:

-txtMenu1
-txtMenu2
_txtMenu3
.....
....

There is also a cursor next to the menu with up/down end enter button.
When I click the down button it moves the selector one space down and up moves it up...

The problem is when i click the down arrow it just moves the selector one space down, when i click it again it does not do anything. Same thing with the up arrow.
The code for the down button is <TAB> and the text boxes tab is in order from 1 to 13...

The second problem is..
When I reach the end (txtMenu13) and click down arrow, the selector goes back to txtMenu1. I need the selector to be blocked there on txtMenu13 so the user has to use the up arrow to go back to txtMenu1. The same thing when the user reaches txtMenu1 and tries to go up one more, he should not be able to do it.
How can i fix this please help!!!
Thank you

Recommended Answers

All 2 Replies

Let me see your codes first.

See if this helps.
2 Buttons, 5 TextBoxes(.Named "txtMenu#")

Public Class Form1
    Private iSelectedTextBox As Integer = 1 '// keeps track of which TextBox is selected.
    Private iFirstTextBox As Integer = 1 '// # of first TextBox, as "txtMenu#".
    Private iLastTextBox As Integer = 5 '// # of last TextBox, as "txtMenu#".  i only used 5 TextBoxes for this sample project.
    Private sNameOfTextBoxes As String = "txtMenu" '// set only the letters from name of TextBoxes, no #'s.

    '// btnUP.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not iSelectedTextBox = iFirstTextBox Then '// check if the # set by the TextBox in Focus is not the first TextBox.
            iSelectedTextBox -= 1 '// subtract -1 to move to the TextBox above.
            Me.Controls(sNameOfTextBoxes & iSelectedTextBox).Select() '// select TextBox above.
        Else
            Me.Controls(sNameOfTextBoxes & iFirstTextBox).Select() '// if first TextBox, select it.
        End If
    End Sub

    '// btnDOWN.
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Not iSelectedTextBox = iLastTextBox Then '// check if the # set by the TextBox in Focus is not the last TextBox.
            iSelectedTextBox += 1 '// add +1 to move to the TextBox below.
            Me.Controls(sNameOfTextBoxes & iSelectedTextBox).Select() '// select TextBox below.
        Else
            Me.Controls(sNameOfTextBoxes & iLastTextBox).Select() '// if last TextBox, select it.
        End If
    End Sub

    '// when a TextBox gets Focus, it will set the # at the end of the TextBox.Name as the # for the iSelectedTextBox.
    Private Sub _txt_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) _
                            Handles txtMenu1.GotFocus, txtMenu2.GotFocus, txtMenu3.GotFocus, txtMenu4.GotFocus, txtMenu5.GotFocus
        iSelectedTextBox = CInt(CType(sender, TextBox).Name.Substring(7)) '// "txtMenu"=7 char.s.  .Substring will extract only the #'s at end of .Name.
    End Sub
End Class

I only used 5 TextBoxes named "txtMenu#". To make this work for more TextBoxes, add the TextBoxes to the Private Sub _txt_GotFocus event as the other TextBoxes are, and change the # in Private iLastTextBox As Integer = 5 , from 5 to however many TextBoxes you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.