当前位置: 开源爱好者 » 编程教程 » VB教程 » 正文

VB简单范例:带历史记录信息的菜单

VB简单范例:带历史记录信息的菜单,就是可以显示以前打开过文件的记录,方便用户以后再次打开,这个现在在很多软件中都有应用:

显示历史记录

Option Explicit
Dim main As New main_frm
Public max_index As Integer
Public myindex As Integer
Private Sub close_Click()  
Dim FNum As Integer
  Dim strfilename As String
  Dim i As Integer
  On Error Resume Next
  For Each main In Forms '循环语句
    If main.MDIChild = True Then
       Unload main
    End If
  Next
    FNum = FreeFile
  strfilename = App.Path & "\cdxx.ini"
  If Dir(strfilename) <> "" Then Kill strfilename
  Open strfilename For Output As #FNum
       For i = 1 To mnufilelist.Count - 1
           Print #FNum, mnufilelist(i).Caption
       Next
  Close #FNum
  Exit Sub
End Sub
Private Sub MDIForm_Load()
  Dim file As Long
  Dim mystring As String
  Dim s As String
  Dim strfilename As String
  strfilename = App.Path & "\cdxx.ini"
  file = FreeFile()
  On Error Resume Next
  Open strfilename For Input As #file   '打开文件菜单列表
       Do While Not EOF(file)
          Line Input #file, mystring
          If mystring <> "" Then
             max_index = max_index + 1
             Load mnufilelist(max_index)
             mnufilelist(max_index).Caption = mystring
             mnufilelist(max_index).Visible = True
          End If
       Loop
  Close #file '关闭文件菜单列表
End Sub
Private Sub mnufilelist_Click(Index As Integer)
  If mnufilelist(Index).Caption <> "" Then
    Static i As Integer
  If i < 1 Then i = 1
  main_frm.Visible = False
  Dim main As New main_frm
  main.Caption = mnufilelist(Index).Caption
  i = i + 1
  main.Picture = LoadPicture(mnufilelist(Index).Caption)
  main.Show
  End If
End Sub
Private Sub open_Click()  '打开带图形的窗体
  CommonDialog1.Filter = "所有图形文件" & "|*.jpg; *.bmp ; *.ico ;*.gif;*.cur"
  CommonDialog1.ShowOpen
  Static i As Integer
  If i < 1 Then i = 1
  main_frm.Visible = False
  Dim main As New main_frm
  main.Caption = CommonDialog1.FileName
  i = i + 1
  main.Picture = LoadPicture(CommonDialog1.FileName)
  main.Show
  max_index = mnufilelist.Count
  Load mnufilelist(max_index)
  mnufilelist(max_index).Caption = CommonDialog1.FileName
  mnufilelist(max_index).Visible = True
End Sub

CopyRight 2018© 开源爱好者 All Rights Reserved 豫ICP备16030607号 隐私声明 网站地图