Sub Main
Begin Dialog UserDialog 400,203,"弹出式菜单" ,.DialogFunc' %GRID:10,7,1,1
OptionGroup .Group1
OptionButton 30,21,220,14,"左上角位于(XPos,YPos)处",.OptionButton1
OptionButton 220,49,150,21,"右边缘与XPos对齐",.OptionButton2
OptionButton 30,49,140,21,"中心与XPos对齐",.OptionButton3
OptionButton 220,84,150,21,"中心与YPos对齐",.OptionButton4
OptionButton 30,84,140,21,"底与YPos对齐",.OptionButton5
PushButton 60,140,130,28,"弹出菜单",.PushButton1
PushButton 220,140,130,28,"取 消",.PushButton2
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub
Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Dim Items(0 To 2) As String
Dim PopupStyle As Variant
'给一个选项数组
Items(0) = "Item &1" '用&符号确定数值键1为本菜单项的快捷键
Items(1) = "Item &2"
Items(2) = "Item &3"
Select Case Action%
Case 1 ' 对话框初始化
Beep
Case 2 ' 改变值或单击按钮
Select Case DlgItem$
Case "PushButton1" '如果单击“弹出菜单”按钮
'下面根据“Group1”的值判断选择了哪个单选钮
Select Case DlgValue("Group1")
Case 0
PopupStyle=1
Case 1
PopupStyle=8
Case 2
PopupStyle=4
Case 3
PopupStyle=16
Case 4
PopupStyle=32
End Select
'显示弹出式菜单
ShowPopupMenu(Items,PopupStyle)
DialogFunc% = True
Case "PushButton2" '如果单击“取消”按钮
DialogFunc%=False
End Select
End Select
End Function