组件名称
属性
值
Form
Name
frmMain
Caption
菜单例子
Frame
Name
fraStyle
Caption
菜单风格
Label
Name
lblHelp
Caption
在窗体空白处单击鼠标右键
OptionButton
Name
opnStyle
Caption
Window 标准
Index
0
OptionButton
Name
opnStyle
Caption
XP 风格
Index
1
OptionButton
Name
opnStyle
Caption
3D 立体风格
Index
2
OptionButton
Name
opnStyle
Caption
渐变风格
Index
3
OptionButton
Name
opnStyle
Caption
多彩风格
Index
4 其实就是在窗体上添加了一个Frame,然后在Frame里添加OptionButton控件数组,用来设置菜单风格,还有一个Label,上面只显示一行提示文字,非常简单。
(3)窗体代码:
Option Explicit
Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI) As Long Private Type POINTAPI X As Long Y As Long End Type
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' 单击鼠标右建弹出菜单 If Button = vbRightButton Then Dim pos As POINTAPI GetCursorPos pos menu.PopupMenu pos.X, pos.Y, POPUP_LEFTALIGN Or POPUP_TOPALIGN End If
End Sub
Private Sub Form_Unload(Cancel As Integer) ' 释放资源, 卸载窗体 Set menu = Nothing Dim frm As Form For Each frm In Forms Unload frm Next End Sub
Private Sub opnStyle_Click(Index As Integer)
' 设置菜单风格
Select Case Index Case 0 ' Windows 标准 menu.Style = STYLE_WINDOWS Case 1 ' XP 风格 menu.Style = STYLE_XP Case 2 ' 3D 立体风格 menu.Style = STYLE_3D Case 3 ' 渐变风格 menu.Style = STYLE_SHADE Case 4 ' 多彩风格 menu.Style = STYLE_COLORFUL End Select