CodeItBetter Programming Another VB Programming Blog

How to show custom popup menu in a text box

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'Controls - How to show custom popup menu in a text box
'Visual Basic TextBox controls react to right-clicks by showing the standard Edit
'pop-up menu (with the usual commands,  such as Undo,  Copy, Cut, and so on). The
'problem  is that if you  invoke a  PopupMenu  method  from  within  the  TextBox
'Control 's  MouseDown event, your custom pop-up menu will be displayed only after
'the  standard  one,  which is  obviously  undesirable.  You can solve it only by
'resorting to the unorthodox and undocumented technique shown below.

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button And vbRightButton Then
        Text1.Enabled = False
        PopupMenu mnuMyPopup
        Text1.Enabled = True
    End If
End Sub
Filed under: Controls Leave a comment
Comments (1) Trackbacks (0)
  1. I keep getting the error

    Run-time error ’424′:

    Object required


Reply

( Cancel )

 

No trackbacks yet.