Jobs
Author: Ulysses R. Gotera Date Submitted: 1/7/2006 Category: Microsoft Controls Compatibility: .NET This code has been accessed 3915 times.
Email Yourself this snippet:
Note: .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.
Code
public static void HighLightCtrl(Control p_objectCtrl) { // ************************************************** // 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; } } }