当前位置: 源码素材网 » VB教程 » 详情页

VB 6 制作一个简单的弹出式菜单附示例代码

  •   时间:2018-10-09
  • 概述:弹出菜单

这个文章介绍的技巧比较有用吧,几乎每个软件都需要有菜单吧,本示例是在VB建立的窗口中制作一个弹出式菜单,当用户按鼠标右键时则出现弹出式菜单,同时将菜单字体“斜体”(PuItalic)加粗显示:

VERSION 5.00
Begin VB.Form frmMenu
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   165
   ClientTop       =   450
   ClientWidth     =   5370
   BeginProperty Font
      Name            =   "宋体"
      Size            =   36
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   5370
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox txtTitle
      Alignment       =   2  'Center
      BeginProperty Font
         Name            =   "宋体"
         Size            =   26.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1095
      Left            =   120
      TabIndex        =   0
      Text            =   "决策支持系统"
      Top             =   2280
      Width           =   5055
   End
   Begin VB.Menu PuStyle
      Caption         =   "字样"
      Visible         =   0   'False
      Begin VB.Menu PuBolt
         Caption         =   "粗体&b"
      End
      Begin VB.Menu PuItalic
         Caption         =   "斜体&i"
      End
      Begin VB.Menu PuUnder
         Caption         =   "下划线&u"
      End
      Begin VB.Menu PuQuit
         Caption         =   "退出&q"
      End
   End
End
Attribute VB_Name = "frmMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
'改变窗体标题
    Me.Caption = "弹出式菜单"
End Sub
Private Sub PuBolt_Click()
'粗体处理
    Static blnF As Boolean
    blnF = Not blnF
    If blnF Then
        txtTitle.FontBold = True
    Else
        txtTitle.FontBold = False
    End If
End Sub
Private Sub PuItalic_Click()
'斜体处理
    Static blnF As Boolean
    blnF = Not blnF
    If blnF Then
        txtTitle.FontItalic = True
    Else
        txtTitle.FontItalic = False
    End If
End Sub
Private Sub PuQuit_Click()
'退出
    End
End Sub
Private Sub PuUnder_Click()
'下划线处理
    Static blnF As Boolean
    blnF = Not blnF
    If blnF Then
        txtTitle.FontUnderline = True
    Else
        txtTitle.FontUnderline = False
    End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'按鼠标右键则出现弹出式菜单
'将“斜体”(PuItalic)菜单项用粗体显示
    If Button = 2 Then Me.PopupMenu PuStyle, , , , PuItalic
End Sub

    相关声明:

      若“VB 6 制作一个简单的弹出式菜单附示例代码”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。