home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / edit.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  11.7 KB  |  320 lines

  1. VERSION 4.00
  2. Begin VB.Form frmEditor 
  3.    Caption         =   "Text Editor: Untitled"
  4.    ClientHeight    =   4020
  5.    ClientLeft      =   960
  6.    ClientTop       =   2196
  7.    ClientWidth     =   7200
  8.    ClipControls    =   0   'False
  9.    Height          =   4764
  10.    Left            =   912
  11.    LinkTopic       =   "Form2"
  12.    ScaleHeight     =   3753.867
  13.    ScaleMode       =   0  'User
  14.    ScaleWidth      =   7200
  15.    Top             =   1500
  16.    Width           =   7296
  17.    Begin VB.TextBox txtEdit 
  18.       BeginProperty Font 
  19.          name            =   "MS Sans Serif"
  20.          charset         =   1
  21.          weight          =   700
  22.          size            =   12
  23.          underline       =   0   'False
  24.          italic          =   0   'False
  25.          strikethrough   =   0   'False
  26.       EndProperty
  27.       Height          =   4289
  28.       Left            =   -30
  29.       MultiLine       =   -1  'True
  30.       ScrollBars      =   3  'Both
  31.       TabIndex        =   0
  32.       Top             =   -30
  33.       Width           =   7215
  34.    End
  35.    Begin MSComDlg.CommonDialog CMDialog1 
  36.       Left            =   0
  37.       Top             =   0
  38.       _version        =   65536
  39.       _extentx        =   677
  40.       _extenty        =   677
  41.       _stockprops     =   0
  42.       cancelerror     =   -1  'True
  43.    End
  44.    Begin VB.Menu mnuFile 
  45.       Caption         =   "&File"
  46.       Begin VB.Menu mnuFileItem 
  47.          Caption         =   "&New"
  48.          Index           =   0
  49.       End
  50.       Begin VB.Menu mnuFileItem 
  51.          Caption         =   "&Open..."
  52.          Index           =   1
  53.       End
  54.       Begin VB.Menu mnuFileItem 
  55.          Caption         =   "Save &As..."
  56.          Index           =   2
  57.       End
  58.       Begin VB.Menu mnuFileItem 
  59.          Caption         =   "-"
  60.          Index           =   3
  61.       End
  62.       Begin VB.Menu mnuFileItem 
  63.          Caption         =   "E&xit"
  64.          Index           =   4
  65.       End
  66.       Begin VB.Menu mnuFileArray 
  67.          Caption         =   "-"
  68.          Index           =   0
  69.          Visible         =   0   'False
  70.       End
  71.    End
  72.    Begin VB.Menu mnuEdit 
  73.       Caption         =   "&Edit"
  74.       Begin VB.Menu mnuEditItem 
  75.          Caption         =   "Cu&t"
  76.          Index           =   0
  77.          Shortcut        =   ^X
  78.       End
  79.       Begin VB.Menu mnuEditItem 
  80.          Caption         =   "C&opy"
  81.          Index           =   1
  82.          Shortcut        =   ^C
  83.       End
  84.       Begin VB.Menu mnuEditItem 
  85.          Caption         =   "&Paste"
  86.          Index           =   2
  87.          Shortcut        =   ^V
  88.       End
  89.    End
  90.    Begin VB.Menu mnuSettings 
  91.       Caption         =   "&Settings"
  92.       Begin VB.Menu mnuSettingsItem 
  93.          Caption         =   "&Colors"
  94.          Index           =   0
  95.          Begin VB.Menu mnuColorsItem 
  96.             Caption         =   "&BackColor"
  97.             Index           =   0
  98.             Begin VB.Menu mnuBackColorItem 
  99.                Caption         =   "&Red"
  100.                Index           =   0
  101.             End
  102.             Begin VB.Menu mnuBackColorItem 
  103.                Caption         =   "&Green"
  104.                Index           =   1
  105.             End
  106.             Begin VB.Menu mnuBackColorItem 
  107.                Caption         =   "&Blue"
  108.                Index           =   2
  109.             End
  110.          End
  111.          Begin VB.Menu mnuColorsItem 
  112.             Caption         =   "&ForeColor"
  113.             Index           =   1
  114.             Begin VB.Menu mnuForeColorItem 
  115.                Caption         =   "&Red"
  116.                Index           =   0
  117.             End
  118.             Begin VB.Menu mnuForeColorItem 
  119.                Caption         =   "&Green"
  120.                Index           =   1
  121.             End
  122.             Begin VB.Menu mnuForeColorItem 
  123.                Caption         =   "&Blue"
  124.                Index           =   2
  125.                Begin VB.Menu mnuBlueItem 
  126.                   Caption         =   "&Light Blue"
  127.                   Index           =   0
  128.                End
  129.                Begin VB.Menu mnuBlueItem 
  130.                   Caption         =   "&Dark Blue"
  131.                   Index           =   1
  132.                   Begin VB.Menu mnuDarkBlueItem 
  133.                      Caption         =   "&Sea Blue"
  134.                      Index           =   0
  135.                   End
  136.                   Begin VB.Menu mnuDarkBlueItem 
  137.                      Caption         =   "&Midnight Blue"
  138.                      Index           =   1
  139.                   End
  140.                End
  141.             End
  142.          End
  143.       End
  144.       Begin VB.Menu mnuSettingsItem 
  145.          Caption         =   "&Font Sizes"
  146.          Index           =   1
  147.          Begin VB.Menu mnuFontSizesItem 
  148.             Caption         =   "12"
  149.             Checked         =   -1  'True
  150.             Index           =   0
  151.          End
  152.          Begin VB.Menu mnuFontSizesItem 
  153.             Caption         =   "24"
  154.             Index           =   1
  155.          End
  156.       End
  157.    End
  158.    Begin VB.Menu mnuAbout 
  159.       Caption         =   "&About..."
  160.    End
  161. Attribute VB_Name = "frmEditor"
  162. Attribute VB_Creatable = False
  163. Attribute VB_Exposed = False
  164. Private Sub Form_Load()
  165.     ' Change the working directory to the directory where this application is located.
  166.     ChDir App.Path
  167.     ChDrive App.Path
  168.     ' Position the text box.
  169.     txtEdit.Move 0, 0
  170.     ' The form is horizontally and vertically centered when loaded.
  171.     Top = Screen.Height / 2 - Height / 2
  172.     Left = Screen.Width / 2 - Width / 2
  173. End Sub
  174. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  175.     ' The general procedure DoUnLoadPreCheck handles the possible unload options
  176.     ' for all three forms in this sample application.
  177.     DoUnLoadPreCheck UnloadMode
  178. End Sub
  179. Private Sub Form_Resize()
  180.     txtEdit.Width = ScaleWidth
  181.     txtEdit.Height = ScaleHeight
  182. End Sub
  183. Private Sub mnuAbout_Click()
  184.     ' All the CaptionTextn string variables below are concatenated together with the appropriate
  185.     ' line feed characters to display text in the About dialog box.
  186.     CaptionText1 = "This Text Editor sample application illustrates the various menu features available using Visual Basic, including..."
  187.     CaptionText2 = "...submenus, separator bars, access keys, shortcut keys, modal and modeless dialog boxes,"
  188.     CaptionText3 = " MsgBox, showing and hiding forms, disabling controls, invisible controls, check marks,"
  189.     CaptionText4 = " control arrays, and adding and removing menu controls at run time..."
  190.     CaptionText5 = "...and much, much more!"
  191.     frmAbout!lblAbout.Caption = CaptionText1 & Chr$(10) & Chr$(10) & CaptionText2 & CaptionText3 & CaptionText4 & Chr$(10) & Chr$(10) & CaptionText5
  192.     ' The Show method with style = 1 displays the dialog as modal. Unloading the
  193.     ' dialog is handled in the cmdOK_Click event procedure.
  194.     frmAbout.Show 1
  195. End Sub
  196. Private Sub mnuBackColorItem_Click(Index As Integer)
  197.     Select Case Index
  198.         Case 0    ' Set BackColor to Red
  199.             txtEdit.BackColor = RGB(255, 0, 0)
  200.         Case 1    ' Set BackColor to Green
  201.             txtEdit.BackColor = RGB(0, 255, 0)
  202.         Case 2    ' Set BackColor to Blue
  203.             txtEdit.BackColor = RGB(0, 0, 255)
  204.     End Select
  205. End Sub
  206. Private Sub mnuBlueItem_Click(Index As Integer)
  207.     ' If the user chooses Light Blue, then set the Forecolor to light
  208.     ' blue, otherwise do nothing.
  209.     If Index = 0 Then
  210.        txtEdit.ForeColor = RGB(0, 150, 255)
  211.     End If
  212. End Sub
  213. Private Sub mnuDarkBlueItem_Click(Index As Integer)
  214.     Select Case Index
  215.     Case 0
  216.     ' Set ForeColor to Sea Blue.
  217.         txtEdit.ForeColor = RGB(0, 50, 175)
  218.     Case 1
  219.     ' Set ForeColor to Midnight Blue.
  220.         txtEdit.ForeColor = RGB(0, 0, 255)
  221.     End Select
  222. End Sub
  223. Private Sub mnuEdit_Click()
  224.     ' Disable Cut and Copy if no text selected.
  225.     mnuEditItem(0).Enabled = (txtEdit.SelLength > 0)
  226.     mnuEditItem(1).Enabled = (txtEdit.SelLength > 0)
  227. End Sub
  228. Private Sub mnuEditItem_Click(Index As Integer)
  229.     Select Case Index
  230.         Case 0
  231.             ' If Index = 0, user chose Cut.
  232.             Clipboard.Clear
  233.             Clipboard.SetText txtEdit.SelText       ' Copy selected text onto the Clipboard.
  234.             txtEdit.SelText = ""                    ' Clear selected text from the document.
  235.         Case 1
  236.             ' If Index = 1, user chose Copy.
  237.             Clipboard.Clear
  238.             Clipboard.SetText txtEdit.SelText       ' Copy selected text onto Clipboard.
  239.         Case 2
  240.             ' If Index = 2, user chose Paste.
  241.             txtEdit.SelText = Clipboard.GetText()   ' Paste Clipboard text (if any) into document.
  242.     End Select
  243. End Sub
  244. Private Sub mnuFileArray_Click(Index As Integer)
  245.     ' Open the selected file.
  246.     If Index >= 0 Then
  247.         OpenFile (mnuFileArray(Index).Caption)
  248.     End If
  249. End Sub
  250. Private Sub mnuFileItem_Click(Index As Integer)
  251.       
  252. ' CancelError is True
  253. On Error GoTo errhandler
  254. Select Case Index
  255.     ' Check index value of selected menu item.
  256.     Case 0
  257.         ' If index = 0, the user chose New.
  258.         txtEdit.Text = ""               ' Clear the text box.
  259.         Filename = "Untitled"           ' Set the title bar caption to "Text Editor: Untitled"
  260.         frmEditor.Caption = "Text Editor: " & Filename
  261.     Case 1
  262.         ' If index = 1, the user chose Open.
  263.         ' Set filters.
  264.         CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
  265.         ' Specify default filter.
  266.         CMDialog1.FilterIndex = 2
  267.         ' Display the File Open dialog box.
  268.         CMDialog1.ShowOpen
  269.         Filename = CMDialog1.Filename
  270.         OpenFile (Filename)
  271.     Case 2
  272.         ' If index = 2, the user chose Save As.
  273.         ' Set filters.
  274.         CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
  275.         ' Specify default filter.
  276.         CMDialog1.FilterIndex = 2
  277.         ' Display the Save As dialog box.
  278.         CMDialog1.ShowSave
  279.         Filename = CMDialog1.Filename
  280.         CloseFile (Filename)
  281.     Case 3
  282.         ' This menu item is a separator bar, no code needs to be written here
  283.         ' because it cannot be selected and therefore cannot receive a Click event.
  284.     Case 4
  285.         ' If index = 4, the user chose Exit.
  286.         End     ' End this application and return to the Windows operating system.
  287. End Select
  288. errhandler:
  289. ' The user clicked the Cancel button.
  290.     Exit Sub
  291. End Sub
  292. Private Sub mnuFontSizesItem_Click(Index As Integer)
  293. Select Case Index
  294. ' Perform an action based on the Index property value of menu control.
  295.     Case 0
  296.     ' If Index = 0, then the user chose font size 12.
  297.         txtEdit.FontSize = 12               ' Set the FontSize property of the text box to 12.
  298.         mnuFontSizesItem(0).Checked = True  ' Display a check mark next to 12.
  299.         mnuFontSizesItem(1).Checked = False ' Remove the check mark next to 24.
  300.     Case 1
  301.         txtEdit.FontSize = 24               ' Set the FontSize property of the text box to 24.
  302.         mnuFontSizesItem(0).Checked = False ' Remove the check mark next to 12.
  303.         mnuFontSizesItem(1).Checked = True  ' Display a check mark next to 24.
  304. End Select
  305. ' Display the font size next to the Font Size command.
  306. mnuSettingsItem(1).Caption = Left$(mnuSettingsItem(1).Caption, 10) & " " & mnuFontSizesItem(Index).Caption
  307. End Sub
  308. Private Sub mnuForeColorItem_Click(Index As Integer)
  309. Select Case Index
  310.     Case 0
  311.         ' Set ForeColor to Red
  312.         txtEdit.ForeColor = RGB(255, 0, 0)
  313.     Case 1
  314.         ' Set ForeColor to Green
  315.         txtEdit.ForeColor = RGB(0, 255, 0)
  316.     Case 2
  317.         ' No code for this case because submenu is automatically displayed in Case 2.
  318. End Select
  319. End Sub
  320.