?
Solved

vb .net and focus on textbox

Posted on 2003-03-06
1
Medium Priority
?
264 Views
Last Modified: 2010-04-17
this works ok when using the mouse but doesn't work well when trying to use the tab key pressing through more then 3 textbox's

i want the user to know the color is the focused one.




''''This sub would then be called from each Enter and Leave event:
   Private Sub txtExample1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtExample1.Enter
        FormatTextBox(sender)
    End Sub

    Private Sub txtExample1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtExample1.Leave
        FormatTextBox(sender)
    End Sub




Private Sub FormatTextBox(ByRef txtBoxToFormat As TextBox)
        ' Change the format of a TextBox to highlight which
        ' textbox is currently active (has focus).  Changes
        ' forecolor of the passed TextBox to blue when the box
        ' has focus and black when it does not.
        '
        ' txtBoxToFormat was passed ByRef so changes can be
        ' made directly

        ' Check to see if the textbox currently has
        ' the focus or not
        If txtBoxToFormat.Focused Then
            ' We have focus, set the forecolor to blue
            txtBoxToFormat.ForeColor = Color.Blue
        Else
            ' We do not have focus, set the forecolor to black
            txtBoxToFormat.ForeColor = Color.Black
        End If
    End Sub
0
Comment
Question by:aot2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 8084905
Hello

  Try to Add another paramter to determine if fouced or not

your sub will be look like

Private Sub FormatTextBox(ByRef txtBoxToFormat As TextBox, ByVal Focues As Boolean)
       
        If Focues Then
            txtBoxToFormat.ForeColor = Color.Blue
        Else
            txtBoxToFormat.ForeColor = Color.Black
        End If
    End Sub

and call it
 FormatTextBox(sender, True) on Enter event, and change it False on Leave event

this is a quick solution, I didn't test your code
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question