Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

vb .net and focus on textbox

Posted on 2003-03-06
1
Medium Priority
?
266 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

572 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