Results 1 to 20 of 20

Thread: want to select a word from line using right click

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Rawalpindi , Pakistan
    Posts
    37

    Question 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

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Posts
    71

    Re: want to select a word from line using right click

    VB Code:
    1. If Button = 2 Then
    2.  
    3.    'This code will be executed when the user clicks on the right mouse button.
    4.  
    5. End if

    This should work, I hope.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Rawalpindi , Pakistan
    Posts
    37

    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

  4. #4
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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:
    1. Option Explicit
    2. 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
    3. Private Const WM_USER = &H400
    4. Private Const EM_CHARFROMPOS = WM_USER + 39
    5. Private Type POINTL
    6.         x As Long
    7.         y As Long
    8. End Type
    9.  
    10. Private Sub RTB_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    11.     Dim mypoint As POINTL
    12.     Dim Index As Long
    13.     If Button = vbRightButton Then
    14.         mypoint.x = ScaleX(x, vbTwips, vbPixels)
    15.         mypoint.y = ScaleY(y, vbTwips, vbPixels)
    16.         Index = SendMessage(RTB.hwnd, EM_CHARFROMPOS, 0, mypoint)
    17.         RTB.SelStart = Index
    18.     End If
    19. End Sub
    Now it is just like the left mouse button

  5. #5
    Addicted Member
    Join Date
    Sep 2004
    Posts
    237

    Thumbs up Re: want to select a word from line using right click

    Thanks moeur.

    It work.

    Thanks again
    software engineer

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2005
    Location
    Rawalpindi , Pakistan
    Posts
    37

    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.

  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: want to select a word from line using right click

    sorry moeur, but it's not working for me!
    Show Appreciation. Rate Posts.

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: want to select a word from line using right click

    what does Index return?
    how much text is in your RTB?

  9. #9
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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".
    Show Appreciation. Rate Posts.

  10. #10
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: want to select a word from line using right click

    hello??
    Show Appreciation. Rate Posts.

  11. #11
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  12. #12
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  13. #13
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: want to select a word from line using right click

    here's the project.
    Attached Files Attached Files
    Show Appreciation. Rate Posts.

  14. #14
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  15. #15
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: want to select a word from line using right click

    not again!!

    thnx moeur, i will download the package soon.
    Show Appreciation. Rate Posts.

  16. #16
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: want to select a word from line using right click

    very thankful to you mr moeur
    Actually, I think it's Dr moeur...

  17. #17
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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??
    Show Appreciation. Rate Posts.

  18. #18
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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?

  19. #19
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: want to select a word from line using right click

    Quote Originally Posted by moeur
    Sherlock.....
    ....what values are you getting in mypoint.x, and mypoint.y?
    different values depending upon where i right-click in rtb!
    RTB.AutoVerbMenu = False Right?
    yes, it is false.

    Am i doing something wrong? i have to right-click in the RTB only na!!
    Show Appreciation. Rate Posts.

  20. #20
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width