Created
August 12, 2015 14:56
-
-
Save bh3605/1a423bec417202daaeab to your computer and use it in GitHub Desktop.
Gives a textbox an easy way of highlighting when tabbing and clicking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' <summary> | |
''' This class adds two events for easy highlighting when tabbing and clicking. | |
''' Double clicking will unhighlight and leave the cursor at the beginning. | |
''' Uses the click and doubleclick events. | |
''' </summary> | |
public class FocusedTextBox | |
''' <summary> | |
''' Adds two events to the given textbox. Will override | |
''' click and doubleclick events. | |
''' </summary> | |
''' <param name="box">a textbox</param> | |
''' <returns>The referenced textbox.</returns> | |
public function add(byval box as TextBox) as TextBox | |
addhandler box.click, addressof focusedClick | |
addhandler box.doubleclick, addressof focusedDoubleClick | |
return box | |
end function | |
''' <summary> | |
''' Removes the click and doubleclick events from the given textbox. | |
''' </summary> | |
''' <param name="box">the textbox</param> | |
''' <returns>the referenced textbox</returns> | |
public function remove(byval box as TextBox) as TextBox | |
removehandler box.click, addressof focusedClick | |
removehandler box.doubleclick, addressof focusedDoubleClick | |
return box | |
end function | |
private sub focusedClick(sender as object, e as EventArgs) | |
dim activeControl = CType(sender, TextBox) | |
if (activeControl.selectionLength = 0) | |
activeControl.SelectAll() | |
end if | |
end sub | |
private sub focusedDoubleClick(sender as object, e as EventArgs) | |
dim control = CType(sender, TextBox) | |
control.deselectAll() | |
end sub | |
end class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment