home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmEditor
- Caption = "Text Editor: Untitled"
- ClientHeight = 4020
- ClientLeft = 960
- ClientTop = 2196
- ClientWidth = 7200
- ClipControls = 0 'False
- Height = 4764
- Left = 912
- LinkTopic = "Form2"
- ScaleHeight = 3753.867
- ScaleMode = 0 'User
- ScaleWidth = 7200
- Top = 1500
- Width = 7296
- Begin VB.TextBox txtEdit
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 1
- weight = 700
- size = 12
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 4289
- Left = -30
- MultiLine = -1 'True
- ScrollBars = 3 'Both
- TabIndex = 0
- Top = -30
- Width = 7215
- End
- Begin MSComDlg.CommonDialog CMDialog1
- Left = 0
- Top = 0
- _version = 65536
- _extentx = 677
- _extenty = 677
- _stockprops = 0
- cancelerror = -1 'True
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileItem
- Caption = "&New"
- Index = 0
- End
- Begin VB.Menu mnuFileItem
- Caption = "&Open..."
- Index = 1
- End
- Begin VB.Menu mnuFileItem
- Caption = "Save &As..."
- Index = 2
- End
- Begin VB.Menu mnuFileItem
- Caption = "-"
- Index = 3
- End
- Begin VB.Menu mnuFileItem
- Caption = "E&xit"
- Index = 4
- End
- Begin VB.Menu mnuFileArray
- Caption = "-"
- Index = 0
- Visible = 0 'False
- End
- End
- Begin VB.Menu mnuEdit
- Caption = "&Edit"
- Begin VB.Menu mnuEditItem
- Caption = "Cu&t"
- Index = 0
- Shortcut = ^X
- End
- Begin VB.Menu mnuEditItem
- Caption = "C&opy"
- Index = 1
- Shortcut = ^C
- End
- Begin VB.Menu mnuEditItem
- Caption = "&Paste"
- Index = 2
- Shortcut = ^V
- End
- End
- Begin VB.Menu mnuSettings
- Caption = "&Settings"
- Begin VB.Menu mnuSettingsItem
- Caption = "&Colors"
- Index = 0
- Begin VB.Menu mnuColorsItem
- Caption = "&BackColor"
- Index = 0
- Begin VB.Menu mnuBackColorItem
- Caption = "&Red"
- Index = 0
- End
- Begin VB.Menu mnuBackColorItem
- Caption = "&Green"
- Index = 1
- End
- Begin VB.Menu mnuBackColorItem
- Caption = "&Blue"
- Index = 2
- End
- End
- Begin VB.Menu mnuColorsItem
- Caption = "&ForeColor"
- Index = 1
- Begin VB.Menu mnuForeColorItem
- Caption = "&Red"
- Index = 0
- End
- Begin VB.Menu mnuForeColorItem
- Caption = "&Green"
- Index = 1
- End
- Begin VB.Menu mnuForeColorItem
- Caption = "&Blue"
- Index = 2
- Begin VB.Menu mnuBlueItem
- Caption = "&Light Blue"
- Index = 0
- End
- Begin VB.Menu mnuBlueItem
- Caption = "&Dark Blue"
- Index = 1
- Begin VB.Menu mnuDarkBlueItem
- Caption = "&Sea Blue"
- Index = 0
- End
- Begin VB.Menu mnuDarkBlueItem
- Caption = "&Midnight Blue"
- Index = 1
- End
- End
- End
- End
- End
- Begin VB.Menu mnuSettingsItem
- Caption = "&Font Sizes"
- Index = 1
- Begin VB.Menu mnuFontSizesItem
- Caption = "12"
- Checked = -1 'True
- Index = 0
- End
- Begin VB.Menu mnuFontSizesItem
- Caption = "24"
- Index = 1
- End
- End
- End
- Begin VB.Menu mnuAbout
- Caption = "&About..."
- End
- Attribute VB_Name = "frmEditor"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Private Sub Form_Load()
- ' Change the working directory to the directory where this application is located.
- ChDir App.Path
- ChDrive App.Path
- ' Position the text box.
- txtEdit.Move 0, 0
- ' The form is horizontally and vertically centered when loaded.
- Top = Screen.Height / 2 - Height / 2
- Left = Screen.Width / 2 - Width / 2
- End Sub
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
- ' The general procedure DoUnLoadPreCheck handles the possible unload options
- ' for all three forms in this sample application.
- DoUnLoadPreCheck UnloadMode
- End Sub
- Private Sub Form_Resize()
- txtEdit.Width = ScaleWidth
- txtEdit.Height = ScaleHeight
- End Sub
- Private Sub mnuAbout_Click()
- ' All the CaptionTextn string variables below are concatenated together with the appropriate
- ' line feed characters to display text in the About dialog box.
- CaptionText1 = "This Text Editor sample application illustrates the various menu features available using Visual Basic, including..."
- CaptionText2 = "...submenus, separator bars, access keys, shortcut keys, modal and modeless dialog boxes,"
- CaptionText3 = " MsgBox, showing and hiding forms, disabling controls, invisible controls, check marks,"
- CaptionText4 = " control arrays, and adding and removing menu controls at run time..."
- CaptionText5 = "...and much, much more!"
- frmAbout!lblAbout.Caption = CaptionText1 & Chr$(10) & Chr$(10) & CaptionText2 & CaptionText3 & CaptionText4 & Chr$(10) & Chr$(10) & CaptionText5
- ' The Show method with style = 1 displays the dialog as modal. Unloading the
- ' dialog is handled in the cmdOK_Click event procedure.
- frmAbout.Show 1
- End Sub
- Private Sub mnuBackColorItem_Click(Index As Integer)
- Select Case Index
- Case 0 ' Set BackColor to Red
- txtEdit.BackColor = RGB(255, 0, 0)
- Case 1 ' Set BackColor to Green
- txtEdit.BackColor = RGB(0, 255, 0)
- Case 2 ' Set BackColor to Blue
- txtEdit.BackColor = RGB(0, 0, 255)
- End Select
- End Sub
- Private Sub mnuBlueItem_Click(Index As Integer)
- ' If the user chooses Light Blue, then set the Forecolor to light
- ' blue, otherwise do nothing.
- If Index = 0 Then
- txtEdit.ForeColor = RGB(0, 150, 255)
- End If
- End Sub
- Private Sub mnuDarkBlueItem_Click(Index As Integer)
- Select Case Index
- Case 0
- ' Set ForeColor to Sea Blue.
- txtEdit.ForeColor = RGB(0, 50, 175)
- Case 1
- ' Set ForeColor to Midnight Blue.
- txtEdit.ForeColor = RGB(0, 0, 255)
- End Select
- End Sub
- Private Sub mnuEdit_Click()
- ' Disable Cut and Copy if no text selected.
- mnuEditItem(0).Enabled = (txtEdit.SelLength > 0)
- mnuEditItem(1).Enabled = (txtEdit.SelLength > 0)
- End Sub
- Private Sub mnuEditItem_Click(Index As Integer)
- Select Case Index
- Case 0
- ' If Index = 0, user chose Cut.
- Clipboard.Clear
- Clipboard.SetText txtEdit.SelText ' Copy selected text onto the Clipboard.
- txtEdit.SelText = "" ' Clear selected text from the document.
- Case 1
- ' If Index = 1, user chose Copy.
- Clipboard.Clear
- Clipboard.SetText txtEdit.SelText ' Copy selected text onto Clipboard.
- Case 2
- ' If Index = 2, user chose Paste.
- txtEdit.SelText = Clipboard.GetText() ' Paste Clipboard text (if any) into document.
- End Select
- End Sub
- Private Sub mnuFileArray_Click(Index As Integer)
- ' Open the selected file.
- If Index >= 0 Then
- OpenFile (mnuFileArray(Index).Caption)
- End If
- End Sub
- Private Sub mnuFileItem_Click(Index As Integer)
-
- ' CancelError is True
- On Error GoTo errhandler
- Select Case Index
- ' Check index value of selected menu item.
- Case 0
- ' If index = 0, the user chose New.
- txtEdit.Text = "" ' Clear the text box.
- Filename = "Untitled" ' Set the title bar caption to "Text Editor: Untitled"
- frmEditor.Caption = "Text Editor: " & Filename
- Case 1
- ' If index = 1, the user chose Open.
- ' Set filters.
- CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
- ' Specify default filter.
- CMDialog1.FilterIndex = 2
- ' Display the File Open dialog box.
- CMDialog1.ShowOpen
- Filename = CMDialog1.Filename
- OpenFile (Filename)
- Case 2
- ' If index = 2, the user chose Save As.
- ' Set filters.
- CMDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
- ' Specify default filter.
- CMDialog1.FilterIndex = 2
- ' Display the Save As dialog box.
- CMDialog1.ShowSave
- Filename = CMDialog1.Filename
- CloseFile (Filename)
- Case 3
- ' This menu item is a separator bar, no code needs to be written here
- ' because it cannot be selected and therefore cannot receive a Click event.
- Case 4
- ' If index = 4, the user chose Exit.
- End ' End this application and return to the Windows operating system.
- End Select
- errhandler:
- ' The user clicked the Cancel button.
- Exit Sub
- End Sub
- Private Sub mnuFontSizesItem_Click(Index As Integer)
- Select Case Index
- ' Perform an action based on the Index property value of menu control.
- Case 0
- ' If Index = 0, then the user chose font size 12.
- txtEdit.FontSize = 12 ' Set the FontSize property of the text box to 12.
- mnuFontSizesItem(0).Checked = True ' Display a check mark next to 12.
- mnuFontSizesItem(1).Checked = False ' Remove the check mark next to 24.
- Case 1
- txtEdit.FontSize = 24 ' Set the FontSize property of the text box to 24.
- mnuFontSizesItem(0).Checked = False ' Remove the check mark next to 12.
- mnuFontSizesItem(1).Checked = True ' Display a check mark next to 24.
- End Select
- ' Display the font size next to the Font Size command.
- mnuSettingsItem(1).Caption = Left$(mnuSettingsItem(1).Caption, 10) & " " & mnuFontSizesItem(Index).Caption
- End Sub
- Private Sub mnuForeColorItem_Click(Index As Integer)
- Select Case Index
- Case 0
- ' Set ForeColor to Red
- txtEdit.ForeColor = RGB(255, 0, 0)
- Case 1
- ' Set ForeColor to Green
- txtEdit.ForeColor = RGB(0, 255, 0)
- Case 2
- ' No code for this case because submenu is automatically displayed in Case 2.
- End Select
- End Sub
-