Link to home
Start Free TrialLog in
Avatar of ZhangPeng
ZhangPeng

asked on

How to custum TextBox's Popup Menu

I want to display my popup menu, when i use right button click
in a textbox field. I write down such code:

      Private Sub Text1_MouseDown(...)
          If Button = 2 Then
              'MsgBox ("Hello")
              Text1.Text = "Text!!!"
              PopupMenu mnuEdit
          End If
      End Sub

it first show its own menu, and then show my menu.
if you uncomment the Line 3, it will show a MsgBox, and then
show my menu. All these are annoyed.

How to close the default menu, or other solve way?

Thank in advance!!   ^_^

Avatar of Vbmaster
Vbmaster

Use this code:

Private Sub Text1_MouseDown(...)

  If Button = 2 Then
    Text1.Enabled = False
    PopupMenu mnuEdit
    Text1.Enabled = True
  End If
 
End Sub

Private Sub mnuEdit_Click()

  Text1.Enabled = True

End Sub
vbmaster:
   Nice tip...I've used the hook the right mouse with api's and everything but the kitchen sink to do this...it worked but your answer is so simple and effective.

Wayne
Avatar of ZhangPeng

ASKER

I think this is a good idea, but it will change the fore
color of TextBox, how to solve this new problem or have
any more good way is welcome.  

Thank in advance!!   ^_^
You can use Juilette's way I guess if you want to make it hard for ya. ;)

Does my code change the ForeColor? You mean it changes to gray colored (disabled) text? But that shouldn't be noticeable because it will instantly be forced back with the "Text1.Enabled = True" line in the mnuEdit_Click event..
ASKER CERTIFIED SOLUTION
Avatar of Juilette
Juilette

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just remember that sublassing means unstable IDE, and there's no (appearant?) reason why to use sublassing in this example. Or have I missed something?
Vbmaster:
Hey, I had to scramble to find this code on an old disk as  I replaced it with a version of yours because I liked yours better...it's faster, simpler, and the tiny side effect of "disable grey" a person can live with.
As far as subclassing, I believe it's a typo reference......it's ony api and function calling.
In defense of this code, I have used it and haven't had any problems....I guess it would depend on how involved and intermixed your application is.

Wayne
if i call a popupmenu, it will cause a GP error, and exit to system.

I think VB hide many thing, so that not work in all env(and all version of VB).

Thank for all this answer!!!
You are right...VB has a lot of NO No's
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
https://www.experts-exchange.com/jsp/zonesAll.jsp

In efforts to help all Members maintain their open questions, this is a reminder to click your Member Profile, expand your question history and find/update all your Open and Locked questions.
 
Thank you,
Moondancer
Moderator @ Experts Exchange