home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / menus / menus.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-08-09  |  6.1 KB  |  135 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Menu Array Example VB4 32"
  4.    ClientHeight    =   2610
  5.    ClientLeft      =   2685
  6.    ClientTop       =   3210
  7.    ClientWidth     =   5460
  8.    Height          =   3300
  9.    Left            =   2625
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    ScaleHeight     =   2610
  13.    ScaleWidth      =   5460
  14.    Top             =   2580
  15.    Width           =   5580
  16.    Begin RichtextLib.RichTextBox RichTextBox1 
  17.       Height          =   2625
  18.       Left            =   0
  19.       TabIndex        =   0
  20.       Top             =   0
  21.       Width           =   5445
  22.       _Version        =   65536
  23.       _ExtentX        =   9604
  24.       _ExtentY        =   4630
  25.       _StockProps     =   69
  26.       BackColor       =   -2147483643
  27.       ScrollBars      =   3
  28.       TextRTF         =   $"menus.frx":0000
  29.    End
  30.    Begin VB.Menu FileMenuHeader 
  31.       Caption         =   "&File"
  32.       Begin VB.Menu FileMenuItem 
  33.          Caption         =   "&Open"
  34.          Index           =   1
  35.       End
  36.       Begin VB.Menu FileMenuItem 
  37.          Caption         =   "&Save"
  38.          Enabled         =   0   'False
  39.          Index           =   2
  40.       End
  41.       Begin VB.Menu FileMenuItem 
  42.          Caption         =   "-"
  43.          Index           =   3
  44.       End
  45.       Begin VB.Menu FileMenuItem 
  46.          Caption         =   "E&xit"
  47.          Index           =   4
  48.       End
  49.    End
  50. Attribute VB_Name = "Form1"
  51. Attribute VB_Creatable = False
  52. Attribute VB_Exposed = False
  53. Option Explicit
  54. Private Sub FileMenuItem_Click(Index As Integer)
  55.    Dim FileName As String
  56.    'Note: Create this file if it doesn't exist already, or
  57.    'change it to another existing text file on your system.
  58.    'This example only deals with menu arrays, not File
  59.    'Handling nor Error Trapping. If you run the program and
  60.    'the file doesn't exist, choosing "Open" on the File Menu
  61.    'will cause an error.
  62.       
  63.    'Hint: You don't need to exit Visual Basic to create this file.
  64.    'Simply run the program, type something in the RichTextBox1
  65.    'Control and choose "Save" from the File Menu. Once something
  66.    'is typed in the RichTextBox1, the "Save" option will become
  67.    'enabled. This will create the file and make it possible to
  68.    'reopen it.
  69.    'See RichTextBox1|Change for the code on how to enable/disable
  70.    'the Menu Array options for the "Save" function.
  71.    FileName = "c:\test.txt"     '<----------------------
  72.                                                         '
  73.    Select Case Index                                    '
  74.       Case Is = 1   'Open File in RichTextBox1...       '
  75.          RichTextBox1.LoadFile FileName, rtfText   '----'
  76.       Case Is = 2   'Save File in RichTextBox1...       '
  77.          RichTextBox1.SaveFile FileName, rtfText   '----'
  78.       Case Is = 3   'This is the separator bar...
  79.       Case Is = 4   'Exit program...
  80.          End
  81.    End Select
  82. End Sub
  83. Private Sub Form_Resize()
  84.    If Form1.WindowState <> 1 Then   'If Form1 isn't minimized...
  85.       'This code keeps the RichTextBox1 Control "maximized" as the
  86.       'size of the container Form1 is changed. If you stretch or
  87.       'shrink the size of Form1 without this code, the RichTextBox1
  88.       'will stay the same size, causing either an ugly looking program
  89.       '(if you make Form1 bigger), or, hidden controls (if you make
  90.       'Form1 smaller).
  91.       'To get the numbers to use here, just look at the Height and
  92.       'Width Properties for both Form1 and RichTextBox1. Since we
  93.       'always want the RichTextBox1 to fill the form, each time
  94.       'Form1 gets RESIZED, we also change the size of RichTextBox1
  95.       'to match. The difference in Width is 135 twips and the
  96.       'difference in Height is 675 twips. Subtract the difference
  97.       'from Form1 and we get where we want RichTextBox1 to end up.
  98.       'There are 15 twips per pixel (for you graphics people).
  99.       RichTextBox1.Width = Form1.Width - 135   'Resize to match...
  100.       'The next If|Then is a graphics Error Trap. It keeps the user
  101.       'from making Form1 so small that RichTextBox1.Top would be
  102.       'outside of Form1 and cause an error. To see what happens,
  103.       'comment out the If|Then and run the program. Grab the lower
  104.       'righthand corner of Form1 and shrink the entire form as small
  105.       'as possible. The error will bring you right back here. ------
  106.       'We don't need to limit the Width to a minimum number         '
  107.       'of twips. Windows already limits the minimum Width of Forms  '
  108.       'that have a Control Box (the title bar with min|max|close    '
  109.       'buttons). The Startup Form in all Visual Basic programs      '
  110.       'MUST have a Control Box. Since this is the Startup Form      '
  111.       '(actually the ONLY Form), we don't need to worry about it.   '
  112.                                                                     '
  113.       If Form1.Height < 1200 Then                                   '
  114.          Form1.Height = 1200                                        '
  115.       End If                                                        '
  116.                                                                     '
  117.       'We could have just made the number 675, but this way, the    '
  118.       'smallest the user can make Form1 will still allow text in    '
  119.       'RichTextBox1 to be seen. Only a tiny bit, but some.          '
  120.                                                                     '
  121.       RichTextBox1.Height = Form1.Height - 675   '<-----------------'
  122.    End If
  123.       
  124. End Sub
  125. Private Sub RichTextBox1_Change()
  126.    'This code gets executed each time the text in RichTextBox1 changes.
  127.    'It only check to see if there is anything there or not.
  128.    'Note: Carriage Returns (CR) and Line Feeds (LF) count as "something".
  129.    If RichTextBox1.Text = "" Then      'There's nothing in RichTextBox1...
  130.       FileMenuItem(2).Enabled = False  'Turn OFF the "Save" option...
  131.    Else                                'Otherwise...
  132.       FileMenuItem(2).Enabled = True   'Turn ON the "Save" option...
  133.    End If
  134. End Sub
  135.