Use an Easier Autohighlight Method

Use an Easier Autohighlight Method

Most of us have a routine we call to autohighlight the entire contents of a textbox when it receives focus. And most of us type the name of the textbox when we pass it to this routine. Instead of typing the control’s name in each GotFocus event, you can use this sub to highlight the currently active textbox on the passed form. Place this code in a module:

 Sub HiLite(frm As Form)	frm.ActiveControl.SelStart = 0	frm.ActiveControl.SelLength = _		Len(frm.ActiveControl.Text)End Sub

Then place this line of code in your textbox control’s GotFocus() event:

 Private Sub Text1_GotFocus()	HiLite MeEnd Sub

Using this code, you can forget about typing your controls’ names over and over.

See also  Digital Signage Solutions for Agile Software Development Teams

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist