vb.net Select textbox content with Mouse position

Hello guys,

Here is what I am trying to do: I’ve added a .SelectAll() method in the MouseDown event of a textbox and it works well.

Now when the user double clicks, I’d like to unselect the text and set the position where the cursor is.

I don’t know if I’am making myself clear here so here is an example:

Let’s say this is the following text in the textbox: “this is just a test, please do not panic.”

User clicks in the textbox, all the text becomes selected.

Let’s assume the position of the curosr is just before the “j”

The user double click so the text becomes unselected and the cursor position automatically changes to the j.

I know I have to use the .Select(start, length) method with 0 as length value, but how do I find the start value depending of the mouse position ?

I hope you’re not getting confused reading this, English is not my first language :p


Thanks in advance !



You should be able to capture the .MouseDoubleClick event to deactivate the .SelectAll() and start the position.  Here is the MSDN for the .MouseDoubleClickEvent:http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousedoubleclick.aspxThe .SelectionStart() property of the textbox  class should be the easiest way to get the starting point of the position  the mouse  curson is placed.  Here is the TextBox MSDN page.http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox_members.aspx

Obviously my explanations were not very clear :pI know the doubleclick events as well as the selectionstart property, despite what it looks like I’ve been programming for a couple of times. So I have this: Private Sub txtBoxAscenseur_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtBoxAscenseur.MouseDown, TxtBoxChauffage.MouseDown, txtBoxClimatisation.MouseDown, TxtBoxEclairage.MouseDown, txtBoxForcesMotrices.MouseDown, TxtBoxServices.MouseDown

Have you tried unloading that eventhandler on the doubleclick event?