want to select a word from line using right click
I want to select a word from a line of RichTextBox using rightclick of mouse............ is there any way to do this..........
I've sleceted a word from the line of Rich TextBox but by using LEFT click of mouse n = InStrRev(txtSpellCheck.text, " ", txtSpellCheck.SelStart)
this code work fine but only with left button click
but I want to do it with righ click
Re: want to select a word from line using right click
VB Code:
If Button = 2 Then
'This code will be executed when the user clicks on the right mouse button.
End if
This should work, I hope.
Re: want to select a word from line using right click
If Button = 2 Then
n = InStrRev(txtSpellCheck.text, " ", txtSpellCheck.SelStart)
End if
when this code 'll be Exicuted then this statement "txtSpellCheck.SelStart"
'll return 0 because it will simply ignore the right click of mouse . the property only work with left click button
Re: want to select a word from line using right click
I've actually thought about this problem before so thanks for bringing it up so that I could think about it again. Here is some code that will move the cursor position to the spot where you right click
VB Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400
Private Const EM_CHARFROMPOS = WM_USER + 39
Private Type POINTL
x As Long
y As Long
End Type
Private Sub RTB_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim mypoint As POINTL
Dim Index As Long
If Button = vbRightButton Then
mypoint.x = ScaleX(x, vbTwips, vbPixels)
mypoint.y = ScaleY(y, vbTwips, vbPixels)
Index = SendMessage(RTB.hwnd, EM_CHARFROMPOS, 0, mypoint)
RTB.SelStart = Index
End If
End Sub
Now it is just like the left mouse button
Re: want to select a word from line using right click
Thanks moeur.
It work. :)
Thanks again
Re: want to select a word from line using right click
very thankful to you mr moeur
I've tried this code it works fine.
Re: want to select a word from line using right click
sorry moeur, but it's not working for me! :confused:
Re: want to select a word from line using right click
what does Index return?
how much text is in your RTB?
Re: want to select a word from line using right click
Quote:
Originally Posted by moeur
what does Index return?
how much text is in your RTB?
the cursor is going to the start position of the rtb, without selecting anything.
i just entered a random test like "jhsdg jagbdfh kjagbdfg agdhas jakshjaed sadvawghd".
Re: want to select a word from line using right click
Re: want to select a word from line using right click
HG,
I don't know why it works for us but not for you.
Again I ask what value does Index return?
Are you using it with a RichTextBox or just a TextBox?
Upload your project so I can see it.
Re: want to select a word from line using right click
Quote:
Originally Posted by moeur
HG,
I don't know why it works for us but not for you.
Again I ask what value does Index return?
Are you using it with a RichTextBox or just a TextBox?
Upload your project so I can see it.
it's always returning zero.
1 Attachment(s)
Re: want to select a word from line using right click
Re: want to select a word from line using right click
OK your project works OK for me.
I guess the next thing to test would be versions of software.
I'm running Windows XP pro
VB 6.0 SP6
So I've got the RichTextBox control from service pack 6
You can download the service packs for free.
Re: want to select a word from line using right click
not again!!
thnx moeur, i will download the package soon.
Re: want to select a word from line using right click
Quote:
very thankful to you mr moeur
Actually, I think it's Dr moeur... :D
Re: want to select a word from line using right click
Quote:
Originally Posted by moeur
OK your project works OK for me.
I guess the next thing to test would be versions of software.
I'm running Windows XP pro
VB 6.0 SP6
So I've got the RichTextBox control from service pack 6
You can download the service packs for free.
all right Moeur, i downloaded and installed VB SP6 on Win 98. but still nothing. it's still returning "0" Index value?? :confused:
Re: want to select a word from line using right click
Sherlock,
I don't know what else to suggest, your project works when I run it.
what values are you getting in mypoint.x, and mypoint.y?
RTB.AutoVerbMenu = False Right?
Re: want to select a word from line using right click
Quote:
Originally Posted by moeur
Sherlock.....
:D
Quote:
....what values are you getting in mypoint.x, and mypoint.y?
different values depending upon where i right-click in rtb!
Quote:
RTB.AutoVerbMenu = False Right?
yes, it is false.
Am i doing something wrong? i have to right-click in the RTB only na!! :blush:
Re: want to select a word from line using right click
sorry for this post. but i need to make this thread to come to first page.