Shahid Ur Rehman Shahid Ur Rehman - 3 months ago 9
Vb.net Question

select the text of wpf textbox on click

I have implemented mentioned code to select the text of WPF textbox but it doesn't work.
the event which fires is the "PreviewMouseDown"

txtQuantity.SelectionStart = 0
txtQuantity.SelectionLength = txtQuantity.Text.Length

Answer

Assuming that you want to select the text of a textbox, with a click on the textbox itself, this will work.

Event PreviewMouseUp,

Code:

txtQuantity.SelectAll()

or,

txtQuantity.Select(start, length)

The event PreviewMouseDown doesn't work because, the effect done by mouse down is overruled by the event PreviewMouseUp which makes the real "Click". Try holding the mouse button to see this effect.