Hej
Prøv med lidt API.
Opret en form med 2 textbokse (Text1 og Text2) + en label (Label1).
Indsæt følgende kode i formen:
'--SNIP
Const TPM_LEFTALIGN As Long = &H0&
Const MF_STRING As Long = &H0&
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hWnd As Long, ByVal lprc As Any) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Dim hMenu As Long
'Init form
Private Sub Form_Load()
Text1.Text = 0
Label1.Caption = "Angiv antallet af menupunkter."
Text2.Text = ""
End Sub
Private Sub DisplayPopup(x As Single, y As Single)
Dim i As Integer
'Start with destroying the menu
DestroyMenu hMenu
'Create it again. (Better to add and remove items)
hMenu = CreatePopupMenu()
'Add the number of items choosen
For i = 1 To Text1.Text
AppendMenu hMenu, MF_STRING, i, ByVal "Menu Item " & i
Next i
'Track the popup menu
TrackPopupMenu hMenu, TPM_LEFTALIGN, x, y, 0, Me.hWnd, ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Destroy menu
DestroyMenu hMenu
End Sub
Private Sub Text2_Change()
'When writing a "." Show popup
If Right(Text2.Text, 1) = "." Then
Call DisplayPopup(50, 50)
End If
End Sub
'--SNIP
Prøv det og se om der ikke kommer hvad du beder om.
Du fylder selv popup'pen i løkken i DisplayPopup.
mvh
Anton