Advertisement
idsystems

VBBD_Ejercicio 17 Editor con Forms MDI

Feb 6th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '***********************************************************************
  2. 'Agregar el código fuente a los formularios y al módulo bas
  3. '************************************************************************
  4. 'Código fuente a colocar en el Formulario Mdi
  5. '************************************************************************
  6. Option Explicit
  7.  
  8. Private Sub MDIForm_Initialize()
  9. CommonDialog1.Filter = "Documento de texto|*.txt|Todos los Archivos|*.*"
  10. End Sub
  11.  
  12. 'Menú abrir
  13. Private Sub mnuAbrir_Click()
  14.  
  15. On Error GoTo errSub
  16.  
  17. CommonDialog1.ShowOpen
  18.  
  19. If CommonDialog1.FileName <> "" Then
  20.     Set FrmDoc = New frmDocumento
  21.    
  22.     FrmDoc.Show
  23.    
  24.     ActiveForm.Caption = CommonDialog1.FileName
  25.  
  26.     ActiveForm.RichTextBox1.LoadFile CommonDialog1.FileName
  27.  
  28. End If
  29.  
  30. Exit Sub
  31. errSub:
  32.  
  33. Select Case Err.Number
  34. Case 70
  35.       ActiveForm.RichTextBox1.LoadFile CommonDialog1.FileName
  36.       Resume Next
  37. End Select
  38.  
  39. End Sub
  40.  
  41.  
  42.  
  43.  
  44. 'Menu Guardar Como
  45. Private Sub mnuGuarcomo_Click()
  46.  
  47. On Error GoTo errSub
  48.  
  49. If Forms.Count = 1 Then
  50.    MsgBox "No hay documentos para guardar", vbInformation
  51.    Exit Sub
  52. End If
  53.  
  54. CommonDialog1.ShowSave
  55.  
  56. If CommonDialog1.FileName = "" Then Exit Sub
  57. ActiveForm.RichTextBox1.SaveFile CommonDialog1.FileName
  58.  
  59.  
  60. Exit Sub
  61. errSub:
  62.  
  63. Select Case Err.Number
  64.   Case 91
  65.     Resume Next
  66. End Select
  67.  
  68. End Sub
  69.  
  70.  
  71. 'Menú para guardar el archivo
  72. Private Sub mnuGuardar_Click()
  73.  
  74. On Error GoTo errSub
  75.  
  76. If Forms.Count = 1 Then
  77.    MsgBox "No hay documentos para guardar", vbInformation
  78.    Exit Sub
  79. End If
  80. If InStr(1, ActiveForm.Caption, sCaption) Then
  81.     CommonDialog1.ShowSave
  82.     If CommonDialog1.FileName = "" Then Exit Sub
  83.     ActiveForm.RichTextBox1.SaveFile CommonDialog1.FileName
  84. Else
  85.     ActiveForm.RichTextBox1.SaveFile ActiveForm.Caption
  86.    
  87. End If
  88.  
  89. Exit Sub
  90. errSub:
  91.  
  92. Select Case Err.Number
  93.   Case 91
  94.      Resume Next
  95. End Select
  96.  
  97. End Sub
  98.  
  99. 'Menú nuevo archivo
  100. Private Sub mnuNuevo_Click()
  101. Set FrmDoc = New frmDocumento
  102.   nForms = nForms + 1
  103.   FrmDoc.Caption = sCaption & nForms
  104.   FrmDoc.Show
  105. End Sub
  106.  
  107. 'Menú pegar
  108. Private Sub mnuPegar_Click()
  109. On Local Error Resume Next
  110. ActiveForm.RichTextBox1.SelText = Clipboard.GetText
  111. End Sub
  112.  
  113. 'Menú salir
  114. Private Sub mnuSalir_Click()
  115. Set FrmDoc = Nothing
  116. End
  117. End Sub
  118.  
  119. 'Menu para seleccionar todo el texto
  120. Private Sub mnuSeleccionar_Click()
  121. On Local Error Resume Next
  122.  
  123. ActiveForm.RichTextBox1.SelStart = 0
  124. ActiveForm.RichTextBox1.SelLength = Len(ActiveForm.RichTextBox1.Text)
  125.  
  126. End Sub
  127.  
  128.  
  129.  
  130. 'Menú Copiar texto
  131. Private Sub mnuCopiar_Click()
  132. On Local Error Resume Next
  133. Clipboard.SetText ActiveForm.RichTextBox1.SelText
  134. End Sub
  135.  
  136. 'Menú cortar texto
  137. Private Sub mnuCortar_Click()
  138. On Local Error Resume Next
  139. Clipboard.SetText ActiveForm.RichTextBox1.SelText
  140. ActiveForm.RichTextBox1.SelText = ""
  141. End Sub
  142.  
  143. '***********************************************************************
  144. 'Código fuente a colocar en el formulario frmDocumento
  145. '***********************************************************************
  146. Option Explicit
  147.  
  148. Public flagGuardar As Boolean
  149.  
  150.  
  151. Private Sub Form_Resize()
  152. 'Redimensionamos el control RichtextBox al ancho y alto del formulario
  153. RichTextBox1.Move ScaleLeft, ScaleTop, ScaleWidth, ScaleHeight
  154. If WindowState = vbMaximized Then
  155.    'mdiform1.Caption = Me.Caption
  156. Else
  157.    mdiform1.Caption = ""
  158. End If
  159. End Sub
  160.  
  161.  
  162. Private Sub Form_Unload(Cancel As Integer)
  163.  
  164. On Error GoTo errSub
  165.  
  166. Dim ret As Integer
  167.  
  168. If flagGuardar Then
  169.     ret = MsgBox(" Guardar cambios", vbYesNoCancel)
  170. End If
  171.  
  172. Select Case ret
  173.     Case vbYes:
  174.    
  175.         If InStr(1, Me.Caption, sCaption) Then
  176.             CommonDialog1.ShowSave
  177.             RichTextBox1.SaveFile CommonDialog1.FileName
  178.         Else
  179.             RichTextBox1.SaveFile Me.Caption
  180.         End If
  181.     Case vbCancel:
  182.          Exit Sub
  183. End Select
  184.  
  185. Set FrmDoc = Nothing
  186.  
  187.  
  188. Exit sub
  189. errSub:
  190.  
  191. Select Case Err.Number
  192.   Case 75
  193.    Resume Next
  194.    
  195. End Select
  196.  
  197. End Sub
  198.  
  199. Private Sub RichTextBox1_Change()
  200. flagGuardar = True
  201. End Sub
  202.            
  203. '***********************************************************
  204. 'Código fuente a colocar en el Módulo bas
  205. '***********************************************************
  206. Public FrmDoc As frmDocumento
  207. Public nForms As Integer
  208.  
  209. Public Const sCaption = "Nuevo documento sin título "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement