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

Vb制作简单实用的窗口下拉菜单 附代码

  •   时间:2018-10-09
  • 概述:下拉菜单

以下代码向大家演示如何在VB6.0编程环境下建立一个下拉式菜单,这在平时的VB界面设计中是很普遍的功能,希望大家喜欢这个简单的下拉菜单制作范例:

VB 下拉菜单

VERSION 5.00
Begin VB.Form frmMenu
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   5250
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   5250
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox txtTitle
      Alignment       =   2  'Center
      BeginProperty Font
         Name            =   "宋体"
         Size            =   27.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   1095
      Left            =   0
      TabIndex        =   0
      Top             =   1560
      Width           =   5295
   End
   Begin VB.Menu mnuText
      Caption         =   "文本&t"
      Begin VB.Menu mnuDecision
         Caption         =   "决策支持系统&d"
         Shortcut        =   ^A
      End
      Begin VB.Menu mnuVisual
         Caption         =   "可视编程系统&v"
         Shortcut        =   ^B
      End
      Begin VB.Menu mnuSeparator
         Caption         =   "-"
      End
      Begin VB.Menu mnuClean
         Caption         =   "清空&c"
         Shortcut        =   ^C
      End
   End
   Begin VB.Menu mnuFont
      Caption         =   "字体&f"
      Enabled         =   0   'False
      Begin VB.Menu mnuSong
         Caption         =   "宋体&s"
         Checked         =   -1  'True
         Shortcut        =   ^D
      End
      Begin VB.Menu mnuLi
         Caption         =   "隶书&l"
         Shortcut        =   ^E
      End
      Begin VB.Menu mnuKai
         Caption         =   "楷体&k"
         Shortcut        =   ^F
      End
   End
   Begin VB.Menu mnuSize
      Caption         =   "字大小&z"
      Enabled         =   0   'False
      Begin VB.Menu mnu28
         Caption         =   "字号&28"
         Checked         =   -1  'True
         Shortcut        =   ^G
      End
      Begin VB.Menu mnu36
         Caption         =   "字号&36"
         Shortcut        =   ^H
      End
      Begin VB.Menu mnu48
         Caption         =   "字号&48"
         Shortcut        =   ^I
      End
   End
   Begin VB.Menu mnuColor
      Caption         =   "字颜色&o"
      Enabled         =   0   'False
      Begin VB.Menu mnuRed
         Caption         =   "红色&r"
         Checked         =   -1  'True
         Shortcut        =   ^J
      End
      Begin VB.Menu mnuBlue
         Caption         =   "兰色&b"
         Shortcut        =   ^K
      End
   End
   Begin VB.Menu mnuExit
      Caption         =   "退出&x"
   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 mnu28_Click()
'确定文本字号
    txtTitle.FontSize = 28
    mnu28.Checked = True
    mnu36.Checked = False
    mnu48.Checked = False
End Sub
Private Sub mnu36_Click()
'确定文本字号
    txtTitle.FontSize = 36
    mnu28.Checked = False
    mnu36.Checked = True
    mnu48.Checked = False
End Sub
Private Sub mnu48_Click()
'确定文本字号
    txtTitle.FontSize = 48
    mnu28.Checked = False
    mnu36.Checked = False
    mnu48.Checked = True
End Sub
Private Sub mnuBlue_Click()
'文本为兰色
    txtTitle.ForeColor = QBColor(9)
    mnuRed.Checked = False
    mnuBlue.Checked = True
End Sub
Private Sub mnuClean_Click()
'清空文本框
    txtTitle.Text = ""
End Sub
Private Sub mnuDecision_Click()
    txtTitle.Text = "决策支持系统"
'在有了文本的情况下激活有关菜单项:
    mnuFont.Enabled = True
    mnuSize.Enabled = True
    mnuColor.Enabled = True
'字符串太长,无法使用48号字
    mnu48.Visible = False
End Sub
Private Sub mnuExit_Click()
'结束运行
    End
End Sub
Private Sub mnuKai_Click()
    txtTitle.Font = "楷体_GB2312"
    mnuSong.Checked = False
    mnuLi.Checked = False
    mnuKai.Checked = True
End Sub
Private Sub mnuLi_Click()
    txtTitle.Font = "隶书"
    mnuSong.Checked = False
    mnuLi.Checked = True
    mnuKai.Checked = False
End Sub
Private Sub mnuRed_Click()
'文本为红色
    txtTitle.ForeColor = QBColor(12)
    mnuRed.Checked = True
    mnuBlue.Checked = False
End Sub
Private Sub mnuSong_Click()
    txtTitle.Font = "宋体"
    mnuSong.Checked = True
    mnuLi.Checked = False
    mnuKai.Checked = False
End Sub
Private Sub mnuVisual_Click()
    txtTitle.Text = "可视编程系统"
'在有了文本的情况下激活有关菜单项:
    mnuFont.Enabled = True
    mnuSize.Enabled = True
    mnuColor.Enabled = True
'字符串太长,无法使用48号字
    mnu48.Visible = False
End Sub
Private Sub txtTitle_Change()
    If txtTitle = "" Then
'文本框中没有字符,使某些菜单项无效
        mnuFont.Enabled = False
        mnuSize.Enabled = False
        mnuColor.Enabled = False
    Else
'文本框中有字符,使某些菜单项有效
        mnuFont.Enabled = True
        mnuSize.Enabled = True
        mnuColor.Enabled = True
    End If
'对短的字符串,48号字菜单项可见
    If Len(txtTitle) <= 4 Then
        mnu48.Visible = True
    Else
'对长的字符串,48号字菜单项不可见
        mnu48.Visible = False
    End If
End Sub

    相关声明:

      若“Vb制作简单实用的窗口下拉菜单 附代码”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。