Selecting all text within a TextBox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Selecting all text within a TextBox

Post by jimbobukii » Thu Apr 04, 2013 8:34 am

I am trying to work out the command to select all the text within a text box when the mouse enters

i.e.
on mouse enter $textbox1,selectall = $true

regards

User avatar
davidc
Posts: 5838
Joined: Thu Aug 18, 2011 4:56 am

Re: Selecting all text within a TextBox

Post by davidc » Thu Apr 04, 2013 8:52 am

Just add a script block for the Mouse Enter event and use the SelectAll method:
PowerShell Code
Double-click the code block to select all.
$textbox1_MouseEnter={

	$textbox1.SelectAll()

}
David
David
SAPIEN Technologies, Inc.

User avatar
jimbobukii
Posts: 52
Joined: Mon Jan 14, 2013 10:34 pm

Re: Selecting all text within a TextBox

Post by jimbobukii » Thu Apr 04, 2013 9:02 am

thanks but I think you got it wrong
you did however put me on the right track

I was using onmouseenter but should be using
PowerShell Code
Double-click the code block to select all.
$TextBox1_MouseDown=[System.Windows.Forms.MouseEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
	#TODO: Place custom script here
	$TextBox1.SelectAll()
}

Locked