by Ulysses R. Gotera (9 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Sat 1st July 2006
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Highlight or selects the text in a text box or combo box
API Declarations
.Net Language: C#
The code is created in Visual Studio's IDE. Open your Visual Studio or a text editor and copy and paste the code below.
{
// **************************************************
// Description : Higlights a selected text in a TextBox
// or ComboBox control.
// Author : Ulysses R. Gotera
// Date Created : Sunday, January 08, 2006
// Country : Philippines
// **************************************************
int intLength; string strTemp;
TextBox objectTxtBox;
ComboBox objectComboBox;
//
if (p_objectCtrl.CanSelect)
{
if (p_objectCtrl is TextBox)
{
objectTxtBox = (TextBox) p_objectCtrl;
objectTxtBox.SelectionStart = 0;
strTemp = objectTxtBox.Text.Trim();
intLength = strTemp.Length;
if (intLength > 0)
objectTxtBox.SelectionLength = intLength;
}
//
if (p_objectCtrl is ComboBox)
{
objectComboBox = (ComboBox) p_objectCtrl;
objectComboBox.SelectionStart = 0;
strTemp = objectComboBox.Text.Trim();
intLength = strTemp.Length;
if (intLength > 0)
objectComboBox.SelectionLength = intLength;
}
}
}