home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch10 / mdipad / editor.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-07-03  |  7.3 KB  |  246 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form EditorForm 
  4.    Caption         =   "Simple Text Editor"
  5.    ClientHeight    =   5760
  6.    ClientLeft      =   165
  7.    ClientTop       =   450
  8.    ClientWidth     =   7260
  9.    LinkTopic       =   "Form1"
  10.    MDIChild        =   -1  'True
  11.    ScaleHeight     =   5760
  12.    ScaleWidth      =   7260
  13.    Begin VB.TextBox Editor 
  14.       Height          =   5745
  15.       HideSelection   =   0   'False
  16.       Left            =   0
  17.       MultiLine       =   -1  'True
  18.       ScrollBars      =   2  'Vertical
  19.       TabIndex        =   0
  20.       Top             =   0
  21.       Width           =   7230
  22.    End
  23.    Begin MSComDlg.CommonDialog CommonDialog1 
  24.       Left            =   0
  25.       Top             =   0
  26.       _ExtentX        =   847
  27.       _ExtentY        =   847
  28.       _Version        =   393216
  29.       FontSize        =   1.17491e-38
  30.    End
  31.    Begin VB.Menu FileMenu 
  32.       Caption         =   "File"
  33.       Begin VB.Menu FileNew 
  34.          Caption         =   "New"
  35.       End
  36.       Begin VB.Menu FileOpen 
  37.          Caption         =   "Open"
  38.       End
  39.       Begin VB.Menu FileSave 
  40.          Caption         =   "Save"
  41.       End
  42.       Begin VB.Menu FileSaveAs 
  43.          Caption         =   "Save As"
  44.       End
  45.       Begin VB.Menu FileSeparator 
  46.          Caption         =   "-"
  47.       End
  48.       Begin VB.Menu FileExit 
  49.          Caption         =   "Exit"
  50.       End
  51.    End
  52.    Begin VB.Menu EditMenu 
  53.       Caption         =   "Edit"
  54.       Begin VB.Menu EditCopy 
  55.          Caption         =   "Copy"
  56.       End
  57.       Begin VB.Menu EditCut 
  58.          Caption         =   "Cut"
  59.       End
  60.       Begin VB.Menu EditPaste 
  61.          Caption         =   "Paste"
  62.       End
  63.       Begin VB.Menu EditSelect 
  64.          Caption         =   "Select All"
  65.       End
  66.       Begin VB.Menu EditSeparator 
  67.          Caption         =   "-"
  68.       End
  69.       Begin VB.Menu EditFind 
  70.          Caption         =   "Find"
  71.       End
  72.    End
  73.    Begin VB.Menu ProcessMenu 
  74.       Caption         =   "Process"
  75.       Begin VB.Menu ProcessUpper 
  76.          Caption         =   "Upper Case"
  77.       End
  78.       Begin VB.Menu ProcessLower 
  79.          Caption         =   "Lower Case"
  80.       End
  81.       Begin VB.Menu ProcessNumber 
  82.          Caption         =   "Number Lines"
  83.       End
  84.    End
  85.    Begin VB.Menu CustomMenu 
  86.       Caption         =   "Customize"
  87.       Begin VB.Menu CustomFont 
  88.          Caption         =   "Font"
  89.       End
  90.       Begin VB.Menu CustomPage 
  91.          Caption         =   "Page Color"
  92.       End
  93.       Begin VB.Menu CustomText 
  94.          Caption         =   "Text Color"
  95.       End
  96.    End
  97. Attribute VB_Name = "EditorForm"
  98. Attribute VB_GlobalNameSpace = False
  99. Attribute VB_Creatable = False
  100. Attribute VB_PredeclaredId = True
  101. Attribute VB_Exposed = False
  102. '  ******************************
  103. '  ******************************
  104. '  ** MASTERING VB6            **
  105. '  ** by Evangelos Petroutos   **
  106. '  ** SYBEX, 1998              **
  107. '  ******************************
  108. '  ******************************
  109. Option Explicit
  110. Private Sub CustomFont_Click()
  111.     CommonDialog1.Flags = cdlCFBoth
  112.     CommonDialog1.ShowFont
  113.     Editor.Font = CommonDialog1.FontName
  114.     Editor.FontBold = CommonDialog1.FontBold
  115.     Editor.FontItalic = CommonDialog1.FontItalic
  116.     Editor.FontSize = CommonDialog1.FontSize
  117. End Sub
  118. Private Sub CustomPage_Click()
  119.     CommonDialog1.ShowColor
  120.     Editor.BackColor = CommonDialog1.Color
  121. End Sub
  122. Private Sub CustomText_Click()
  123.     CommonDialog1.ShowColor
  124.     Editor.ForeColor = CommonDialog1.Color
  125. End Sub
  126. Private Sub EditCopy_Click()
  127.     Clipboard.SetText Editor.SelText
  128. End Sub
  129. Private Sub EditCut_Click()
  130.     Clipboard.SetText Editor.SelText
  131.     Editor.SelText = ""
  132. End Sub
  133. Private Sub EditFind_Click()
  134.     Form2.Show
  135. End Sub
  136. Private Sub EditPaste_Click()
  137.     Editor.SelText = Clipboard.GetText
  138. End Sub
  139. Private Sub EditSelect_Click()
  140.     Editor.SelStart = 0
  141.     Editor.SelLength = Len(Editor.Text)
  142. End Sub
  143. Private Sub FileExit_Click()
  144.     Unload MDIForm1
  145.     End
  146. End Sub
  147. Private Sub FileNew_Click()
  148.     MDIForm1.MDINew_Click
  149. End Sub
  150. Private Sub FileOpen_Click()
  151.     MDIForm1.MDIOpen_Click
  152. ' CALL THE FORM'S RESIZE METHOD TO MAKE SURE
  153. ' THE VERTICAL SCROLLBAR IS VISIBLE
  154.     Form_Resize
  155. End Sub
  156. Private Sub FileSave_Click()
  157. Dim FNum As Integer
  158. Dim txt As String
  159.     If OpenFile = "" Then
  160.         FileSaveAs_Click
  161.         Exit Sub
  162.     End If
  163. On Error GoTo FileError
  164.     FNum = FreeFile
  165.     Open OpenFiles(currentDocument) For Output As #1
  166.     Print #FNum, Editor.Text
  167.     Close #FNum
  168.     Exit Sub
  169. FileError:
  170.     If Err.Number = cdlCancel Then Exit Sub
  171.     MsgBox "Unkown error while saving file " & OpenFiles(currentDocument)
  172.     OpenFiles(currentDocument) = ""
  173. End Sub
  174. Private Sub FileSaveAs_Click()
  175. Dim FNum As Integer
  176. Dim txt As String
  177. On Error GoTo FileError
  178.     CommonDialog1.CancelError = True
  179.     CommonDialog1.Flags = cdlOFNOverwritePrompt
  180.     CommonDialog1.DefaultExt = "TXT"
  181.     CommonDialog1.Filter = "Text files|*.TXT|All files|*.*"
  182.     CommonDialog1.ShowSave
  183.     FNum = FreeFile
  184.     Open CommonDialog1.FileName For Output As #1
  185.     Print #FNum, Editor.Text
  186.     Close #FNum
  187.     OpenFiles(currentDocument) = CommonDialog1.FileName
  188.     DocumentForms(currentDocument).Caption = OpenFiles(currentDocument)
  189.     Exit Sub
  190. FileError:
  191.     If Err.Number = cdlCancel Then Exit Sub
  192.     MsgBox "Unkown error while saving file " & CommonDialog1.FileName
  193.     OpenFiles(currentDocument) = ""
  194. End Sub
  195. Private Sub Form_GotFocus()
  196.     currentDocument = Me.Tag
  197. End Sub
  198. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  199. Dim reply As Integer
  200.     reply = MsgBox("Are you sure you want to close the document " & Me.Tag, _
  201.     vbYesNoCancel + vbInformation)
  202.     If reply = vbCancel Then
  203.         Cancel = True
  204.     ElseIf reply = vbYes Then Exit Sub
  205.     Else
  206.         FileSaveAs_Click
  207.     End If
  208. End Sub
  209. ' THE RESIZE METHOD IS PUBLIC BECAUSE IT MUST
  210. ' BE CALLED FROM OUTSIDE THIS FORM
  211. Public Sub Form_Resize()
  212.     DocumentForms(currentDocument).Editor.Width = DocumentForms(currentDocument).Width - 10 * Screen.TwipsPerPixelX
  213.     DocumentForms(currentDocument).Editor.Height = DocumentForms(currentDocument).Height - 30 * Screen.TwipsPerPixelX
  214. End Sub
  215. Private Sub ProcessLower_Click()
  216. Dim Sel1 As Integer, Sel2 As Integer
  217.     Sel1 = Editor.SelStart
  218.     Sel2 = Editor.SelLength
  219.     Editor.SelText = LCase$(Editor.SelText)
  220.     Editor.SelStart = Sel1
  221.     Editor.SelLength = Sel2
  222. End Sub
  223. Private Sub ProcessNumber_Click()
  224. Dim tmpText As String, tmpLine As String
  225. Dim firstChar As Integer, lastChar As Integer
  226. Dim currentLine As Integer
  227. firstChar = 1
  228. currentLine = 1
  229. lastChar = InStr(Editor.Text, Chr$(10))
  230. While lastChar > 0
  231.     tmpLine = Format$(currentLine, "000") & "  " & Mid$(Editor.Text, firstChar, lastChar - firstChar + 1)
  232.     currentLine = currentLine + 1
  233.     firstChar = lastChar + 1
  234.     lastChar = InStr(firstChar, Editor.Text, Chr$(10))
  235.     tmpText = tmpText + tmpLine
  236. Editor.Text = tmpText
  237. End Sub
  238. Private Sub ProcessUpper_Click()
  239. Dim Sel1 As Integer, Sel2 As Integer
  240.     Sel1 = Editor.SelStart
  241.     Sel2 = Editor.SelLength
  242.     Editor.SelText = UCase$(Editor.SelText)
  243.     Editor.SelStart = Sel1
  244.     Editor.SelLength = Sel2
  245. End Sub
  246.