I created an event handler for the Textbox.Enter event
, which selects a part of the text inside the textbox, like this:
TextBox1.Select(3,5);
The result looks like this:
When the Textbox is entered via the Keyboard via [Tab] or [Shift]-[Tab],
the part of the text that needs to be selected is selected well, just like in the screenshot above.
However if the textbox is entered not via the keyboard but via the mouse,
then nothing is selected:
It seems that what happens is this:
When we enter the textbox with the mouse,
the click indeed raises the Enter event
, but the mouseclick also sets the location of the cursor, to the location the user clicked with the mouse, inside the textbox.
And this setting of the cursor happens right after the event handler was ran.
So this means, that the selection that the event handler performed (with the TextBox1.Select(3,5);
line), is overridden by the mouse's location,
and that's why entering the textbox with the mouse, appears to not select anything.
My question:
How can I make the mouse indeed raise the Enter event
, yet not change the cursor position inside the textbox?
So I will then be able to have my selection (that happens in code) remain and not be overridden..
Edit:
The purpose of this is to enable easy selection of the MM:SS part of the time, which is usually the part that is being edited (the HH or mmm parts are rarely changed).