|
-
Feb 25th, 2006, 09:09 AM
#1
Thread Starter
Hyperactive Member
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"
-
Feb 25th, 2006, 11:08 AM
#2
Thread Starter
Hyperactive Member
Re: Right click textbox?
actually, it doesn't have to be a textbox. it can be a richtextbox too
-
Feb 25th, 2006, 11:10 AM
#3
Hyperactive Member
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
-
Feb 25th, 2006, 11:28 AM
#4
Thread Starter
Hyperactive Member
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.
-
Feb 25th, 2006, 11:38 AM
#5
Thread Starter
Hyperactive Member
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?
-
Feb 25th, 2006, 12:08 PM
#6
Re: Right click textbox?
You mean from point a to point b? Mid$(text,a,b-a+1).
-
Feb 25th, 2006, 12:11 PM
#7
Thread Starter
Hyperactive Member
Re: Right click textbox?
 Originally Posted by Al42
You mean from point a to point b? Mid$(text,a,b-a+1).
yea thanks alot!
-
Feb 25th, 2006, 12:19 PM
#8
Thread Starter
Hyperactive Member
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?
-
Feb 25th, 2006, 10:26 PM
#9
Frenzied Member
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:
Option Explicit
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Text1.Enabled = False
Text1.Enabled = True
Text1.SetFocus
PopupMenu mnuTextRightClick
End If
End Sub
back to your question......solution:
VB Code:
Option Explicit
Private Sub Form_Load()
Text1.Text = "Hey what's up"
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim word, replaced As String
If Button = vbRightButton Then
If Text1.SelLength > 0 Then
word = Text1.SelText
replaced = InputBox("What world would you like to replace """ _
& word & _
""" it with?" _
, " Replace", "dude ")
If replaced = "" Then
Exit Sub
Else
Text1.Text = Replace(Text1.Text, word, replaced)
End If
Else
Text1.Enabled = False
Text1.Enabled = True
Text1.SetFocus
PopupMenu MnuElse 'must place a menu or the regular
'menu will comeup insted which is
'what you don't want to happen
End If
End If
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.
-
Feb 26th, 2006, 01:06 AM
#10
Thread Starter
Hyperactive Member
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:
Option Explicit
Private Sub Form_Load()
Text1.Text = "Hey what's up"
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim word, replaced As String
If Button = vbRightButton Then
If Text1.SelLength > 0 Then
word = Text1.SelText
replaced = InputBox("What world would you like to replace """ _
& word & _
""" it with?" _
, " Replace", "dude ")
If replaced = "" Then
Exit Sub
Else
Text1.Text = Replace(Text1.Text, word, replaced)
End If
Else
Text1.Enabled = False
Text1.Enabled = True
Text1.SetFocus
PopupMenu MnuElse 'must place a menu or the regular
'menu will comeup insted which is
'what you don't want to happen
End If
End If
End Sub
-
Feb 26th, 2006, 01:42 AM
#11
Hyperactive Member
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
-
Feb 26th, 2006, 02:51 AM
#12
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|