Results 1 to 12 of 12

Thread: Right click textbox?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Right click textbox?

    is something like this possible in vb?

    I have this in a textbox "Hey what's up"

    I would like to high the word "what's", right click it and have a input box that says "Please enter the word you would like to replace it with". the user enters "dude" and the original textbox will go from "hey what's up" to "hey dude up"

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    actually, it doesn't have to be a textbox. it can be a richtextbox too

  3. #3
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: Right click textbox?

    create a menupopup then use the seltext of the text box then replace it with the value of the input box

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    ok i got everything working besides the replace function.

    like what if i had a textbox "what what up" and wanted to replace the word "what" it'll replace both of them
    Last edited by Whatupdoc; Feb 25th, 2006 at 11:33 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    hmm i just thought of a good idea that will work (it's a bit hard to explain in details), but i need help with something.

    How would i grab text from a textbox from length a to length b?

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Right click textbox?

    You mean from point a to point b? Mid$(text,a,b-a+1).

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    Quote Originally Posted by Al42
    You mean from point a to point b? Mid$(text,a,b-a+1).
    yea thanks alot!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    one more question, when i right click a textbox. two menu shows up. the first one is the original one that comes with windows. you know that one that says "copy, paste, etc..."

    the second one is the one i implemented:
    If Button = vbRightButton Then
    PopupMenu mnuButton
    End If

    how do i disable the first menu?

  9. #9
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Right click textbox?

    The easiest way of making a custom right click menu toa text box is making your own menu make sure its set to visible false then add this code

    since adding a right click menu will cuse the default menu to show you will need to disable it and enable it. like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.     If Button = vbRightButton Then
    5.         Text1.Enabled = False
    6.         Text1.Enabled = True
    7.         Text1.SetFocus
    8.         PopupMenu mnuTextRightClick
    9.     End If
    10. End Sub

    back to your question......solution:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Text1.Text = "Hey what's up"
    5. End Sub
    6.  
    7. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    8. Dim word, replaced As String
    9.     If Button = vbRightButton Then
    10.         If Text1.SelLength > 0 Then
    11.             word = Text1.SelText
    12.             replaced = InputBox("What world would you like to replace """ _
    13.                         & word & _
    14.                                 """ it with?" _
    15.                         , " Replace", "dude ")
    16.             If replaced = "" Then
    17.                 Exit Sub
    18.             Else
    19.                 Text1.Text = Replace(Text1.Text, word, replaced)
    20.             End If
    21.         Else
    22.                 Text1.Enabled = False
    23.                 Text1.Enabled = True
    24.                 Text1.SetFocus
    25.                 PopupMenu MnuElse 'must place a menu or the regular
    26.                                   'menu will comeup insted which is
    27.                                   'what you don't want to happen
    28.     End If
    29.     End If
    30. End Sub

    You should realy be a ware that the you can use the deault "Find and Replace Dialog" http://www.vbforums.com/showthread.p...+Common+Dialog
    Last edited by wiz126; Feb 25th, 2006 at 10:44 PM.
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    cool thanks alot, but this part won't work if text1.text = "what what up dude" and i wanted to replace the word "what"

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Text1.Text = "Hey what's up"
    5. End Sub
    6.  
    7. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    8. Dim word, replaced As String
    9.     If Button = vbRightButton Then
    10.         If Text1.SelLength > 0 Then
    11.             word = Text1.SelText
    12.             replaced = InputBox("What world would you like to replace """ _
    13.                         & word & _
    14.                                 """ it with?" _
    15.                         , " Replace", "dude ")
    16.             If replaced = "" Then
    17.                 Exit Sub
    18.             Else
    19.                 Text1.Text = Replace(Text1.Text, word, replaced)
    20.             End If
    21.         Else
    22.                 Text1.Enabled = False
    23.                 Text1.Enabled = True
    24.                 Text1.SetFocus
    25.                 PopupMenu MnuElse 'must place a menu or the regular
    26.                                   'menu will comeup insted which is
    27.                                   'what you don't want to happen
    28.     End If
    29.     End If
    30. End Sub

  11. #11
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: Right click textbox?

    use the seltext of the text box
    if you highlight "what" just isuue the seltext on your menu popup
    Text1.SelText = word

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Right click textbox?

    yea i'm talking about when your replacing words, it'll replace all of it instead of just one word.

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