FANDOM


Formulario secundario Editar

Public Class frmEditoraHija

  Public sNombre As String
  Public bModificada As Boolean
  Public iNumero As Integer
  Public bSaliendo As Boolean

  Private Sub frmEditoraHija_FormClosing( _
    ByVal sender As Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs _
  ) Handles Me.FormClosing

    If e.CloseReason = CloseReason.UserClosing Then
      Call frmEditoraMadre.ArchivoCerrar()
    End If
    e.Cancel = Not bSaliendo

  End Sub

  Private Sub txtEditora_TextChanged( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles txtEditora.TextChanged

    bModificada = True

  End Sub

End Class

Formulario principal Editar

Option Explicit On

Public Class frmEditoraMadre

  Dim cfrmHijas As New Collection
  Dim iHijas As Integer = 0
  Dim bSaliendo As Boolean = False

  Sub Desactivados()

    mnuArchivoCerrar.Enabled = False
    mnuArchivoGuardar.Enabled = False
    mnuArchivoGuardarComo.Enabled = False
    mnuEdicion.Enabled = False
    mnuFuente.Enabled = False
    mnuVentana.Enabled = False

    btnGuardar.Enabled = False
    btnCortar.Enabled = False
    btnCopiar.Enabled = False
    btnPegar.Enabled = False
    btnNegrita.Enabled = False
    btnCursiva.Enabled = False
    btnSubrayado.Enabled = False

  End Sub

  Sub Activados()

    mnuArchivoCerrar.Enabled = True
    mnuArchivoGuardar.Enabled = True
    mnuArchivoGuardarComo.Enabled = True
    mnuEdicion.Enabled = True
    mnuFuente.Enabled = True
    mnuVentana.Enabled = True

    btnGuardar.Enabled = True
    btnCortar.Enabled = True
    btnCopiar.Enabled = True
    btnPegar.Enabled = True
    btnNegrita.Enabled = True
    btnCursiva.Enabled = True
    btnSubrayado.Enabled = True

  End Sub

  Function DeseaGuardar( _
    ByVal bCancelar As Boolean _
  ) As Integer

    Dim sMensaje As String
    sMensaje = "El texto del archivo "

    Dim frmHija As frmEditoraHija
    frmHija = ActiveMdiChild
    If frmHija.sNombre = "" Then
      sMensaje &= "Sin título"
    Else
      sMensaje &= frmHija.sNombre
    End If

    sMensaje &= _
      " ha cambiado." & vbCrLf & vbCrLf & _
      "¿Desea guardar los cambios?"

    Dim iBotones As Integer
    iBotones = vbQuestion
    If bCancelar = True Then
      iBotones = iBotones Or vbYesNoCancel
    Else
      iBotones = iBotones Or vbYesNo
    End If

    DeseaGuardar = MsgBox( _
      sMensaje, iBotones, "Editora" _
    )

  End Function

  Sub ArchivoAbrir()

    With dlgAbrir
      .Filter = "Documentos de texto|*.txt"
      .ShowDialog()
    End With

    ArchivoNuevo(dlgAbrir.FileName)

    Dim frmHija As frmEditoraHija
    frmHija = ActiveMdiChild

    With frmHija
      .sNombre = dlgAbrir.FileName
      .Text = .sNombre
      Cursor = Cursors.WaitCursor
      .txtEditora.Text = _
        My.Computer.FileSystem.ReadAllText( _
          .sNombre _
        )
      Cursor = Cursors.Default
      .bModificada = False
    End With

    Activados()

  End Sub

  Sub ArchivoCerrar()

    Dim bCancelar As Boolean
    If bSaliendo = True Then
      bCancelar = False
    Else
      bCancelar = True
    End If

    Dim frmHija As frmEditoraHija
    frmHija = ActiveMdiChild

    If frmHija.bModificada = True Then
      Select Case DeseaGuardar(bCancelar)
        Case vbCancel
          Exit Sub
        Case vbYes
          ArchivoGuardar()
      End Select
    End If

    cfrmHijas.Remove(CStr(frmHija.iNumero))
    frmHija.bSaliendo = True

    If cfrmHijas.Count = 0 Then
      Desactivados()
    End If

  End Sub

  Sub ArchivoGuardar()

    Dim frmHija As frmEditoraHija
    frmHija = ActiveMdiChild

    If frmHija.sNombre = "" Then
      With dlgGuardar
        .Filter = "Documentos de texto|*.txt"
        .ShowDialog()
        frmHija.sNombre = .FileName
        frmHija.Text = .FileName
      End With
    End If

    With frmHija
      Cursor = Cursors.WaitCursor
      My.Computer.FileSystem.WriteAllText( _
        .sNombre, .txtEditora.Text, False _
      )
      Cursor = Cursors.Default
      .bModificada = False
    End With

  End Sub

  Sub ArchivoNuevo(Optional ByVal sTitulo As String = "")

    iHijas += 1

    Dim frmHija As New frmEditoraHija
    With frmHija
      If sTitulo = "" Then
        .Text = "Sin título " & iHijas
      Else
        .Text = sTitulo
      End If
      .iNumero = iHijas
      .MdiParent = Me
      .Show()
    End With

    cfrmHijas.Add(frmHija, CStr(iHijas))

    Activados()

  End Sub

  Sub ArchivoSalir()

    Dim iBoton As Integer
    iBoton = MsgBox( _
      "¿Desea salir?", _
      vbQuestion Or vbYesNo, _
      "Editora" _
    )

    If iBoton = vbYes Then

      bSaliendo = True

      Dim frmHija As frmEditoraHija
      For Each frmHija In cfrmHijas
        frmHija.Focus()
        ArchivoCerrar()
      Next
      End

    End If

  End Sub

  Sub EdicionCortar()

    Dim frmEditora As frmEditoraHija
    frmEditora = ActiveMdiChild

    Dim aDataObject As New DataObject
    aDataObject.SetData( _
      DataFormats.Text, _
      frmEditora.txtEditora.SelectedText _
    )
    Clipboard.SetDataObject(aDataObject)

    frmEditora.txtEditora.SelectedText = ""

  End Sub

  Sub EdicionCopiar()

    Dim frmEditora As frmEditoraHija
    frmEditora = ActiveMdiChild

    Dim aDataObject As New DataObject
    aDataObject.SetData( _
      DataFormats.Text, _
      frmEditora.txtEditora.SelectedText _
    )
    Clipboard.SetDataObject(aDataObject)

  End Sub

  Sub EdicionPegar()

    Dim frmEditora As frmEditoraHija
    frmEditora = ActiveMdiChild

    'txtEditora.SelectedText = Clipboard.GetText

    If Clipboard.GetDataObject.GetDataPresent( _
      DataFormats.Text _
    ) Then

      frmEditora.txtEditora.SelectedText = _
        System.Windows.Forms.Clipboard.GetDataObject.GetData( _
        DataFormats.Text _
      )

    End If


  End Sub

  Sub FuenteCambiar()

    dlgFuente.ShowDialog()

    Dim txtEditora As TextBox
    txtEditora = ActiveMdiChild.ActiveControl

    With txtEditora

      .Font = dlgFuente.Font

      .Font = New Font(dlgFuente.Font, FontStyle.Regular)

      mnuFuenteNegrita.Checked = False
      mnuFuenteCursiva.Checked = False
      mnuFuenteSubrayado.Checked = False
      btnNegrita.Checked = False
      btnCursiva.Checked = False
      btnSubrayado.Checked = False

      If dlgFuente.Font.Bold = True Then
        Call FuenteNegrita()
      End If

      If dlgFuente.Font.Italic = True Then
        Call FuenteCursiva()
      End If

      If dlgFuente.Font.Underline = True Then
        Call FuenteSubrayado()
      End If

    End With

  End Sub

  Sub FuenteNormal()

    Dim txtEditora As TextBox
    txtEditora = ActiveMdiChild.ActiveControl

    txtEditora.Font = New Font( _
      txtEditora.Font, FontStyle.Regular _
    )

    mnuFuenteNegrita.Checked = False
    mnuFuenteCursiva.Checked = False
    mnuFuenteSubrayado.Checked = False

    btnNegrita.Checked = False
    btnCursiva.Checked = False
    btnSubrayado.Checked = False

  End Sub

  Sub FuenteNegrita()

    Dim b As Boolean

    Dim txtEditora As TextBox
    txtEditora = ActiveMdiChild.ActiveControl

    With txtEditora
      b = Not .Font.Bold
      If b = True Then
        .Font = New Font( _
          .Font, .Font.Style Or FontStyle.Bold _
        )
      Else
        .Font = New Font( _
          .Font, .Font.Style And (Not FontStyle.Bold) _
        )
      End If
    End With

    mnuFuenteNegrita.Checked = b
    btnNegrita.Checked = b

  End Sub

  Sub FuenteCursiva()

    Dim b As Boolean

    Dim txtEditora As TextBox
    txtEditora = ActiveMdiChild.ActiveControl

    With txtEditora
      b = Not .Font.Italic
      If b = True Then
        .Font = New Font( _
          .Font, .Font.Style Or FontStyle.Italic _
        )
      Else
        .Font = New Font( _
          .Font, .Font.Style And (Not FontStyle.Italic) _
        )
      End If
    End With

    mnuFuenteCursiva.Checked = b
    btnCursiva.Checked = b

  End Sub

  Sub FuenteSubrayado()

    Dim b As Boolean

    Dim txtEditora As TextBox
    txtEditora = ActiveMdiChild.ActiveControl

    With txtEditora
      b = Not .Font.Underline
      If b = True Then
        .Font = New Font( _
          .Font, .Font.Style Or FontStyle.Underline _
        )
      Else
        .Font = New Font( _
          .Font, .Font.Style And (Not FontStyle.Underline) _
        )
      End If
    End With

    mnuFuenteSubrayado.Checked = b
    btnSubrayado.Checked = b

  End Sub

  Sub AyudaAcercaDe()

    Dim sMensaje As String
    sMensaje = _
      "Editora - programado por un enrea"
    MsgBox( _
      sMensaje, _
      vbOKOnly Or vbInformation, _
      "Editora" _
    )

  End Sub

  Private Sub frmEditoraMadre_Load( _
    ByVal sender As Object, _
    ByVal e As System.EventArgs _
  ) Handles Me.Load

    Desactivados()

  End Sub

  Private Sub frmEditoraMadre_FormClosing( _
    ByVal sender As Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs _
  ) Handles Me.FormClosing

    If e.CloseReason = CloseReason.UserClosing Then
      ArchivoSalir()
    End If

    e.Cancel = Not bSaliendo

  End Sub




  Private Sub mnuArchivoNuevo_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles mnuArchivoNuevo.Click

    ArchivoNuevo()

  End Sub

  Private Sub mnuArchivoAbrir_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles mnuArchivoAbrir.Click

    ArchivoAbrir()

  End Sub

  Private Sub mnuArchivoCerrar_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles mnuArchivoCerrar.Click

    ArchivoCerrar()

  End Sub

  Private Sub mnuArchivoGuardar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuArchivoGuardar.Click

    ArchivoGuardar()

  End Sub

  Private Sub mnuArchivoGuardarComo_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles mnuArchivoGuardarComo.Click

    ArchivoGuardar()

  End Sub

  Private Sub mnuArchivoSalir_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles mnuArchivoSalir.Click

    ArchivoSalir()

  End Sub

  Private Sub mnuEdicionCortar_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
  ) Handles mnuEdicionCortar.Click

    EdicionCortar()

  End Sub

  Private Sub mnuEdicionCopiar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuEdicionCopiar.Click

    EdicionCopiar()

  End Sub

  Private Sub mnuEdicionPegar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuEdicionPegar.Click

    EdicionPegar()

  End Sub

  Private Sub mnuFuenteCambiar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuFuenteCambiar.Click

    FuenteCambiar()

  End Sub

  Private Sub mnuFuenteNormal_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuFuenteNormal.Click

    FuenteNormal()

  End Sub

  Private Sub mnuFuenteNegrita_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuFuenteNegrita.Click

    FuenteNegrita()

  End Sub

  Private Sub mnuFuenteCursiva_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuFuenteCursiva.Click

    FuenteCursiva()

  End Sub

  Private Sub mnuFuenteSubrayado_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuFuenteSubrayado.Click

    FuenteSubrayado()

  End Sub

  Private Sub mnuVentanaMosaicoHorizontal_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuVentanaMosaicoHorizontal.Click

    LayoutMdi(MdiLayout.TileHorizontal)

  End Sub

  Private Sub mnuVentanaMosaicoVertical_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuVentanaMosaicoVertical.Click

    LayoutMdi(MdiLayout.TileVertical)

  End Sub

  Private Sub mnuVentanaCascada_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuVentanaCascada.Click

    LayoutMdi(MdiLayout.Cascade)

  End Sub

  Private Sub mnuVentanaOrganizarIconos_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuVentanaOrganizarIconos.Click

    LayoutMdi(MdiLayout.ArrangeIcons)

  End Sub

  Private Sub mnuAyudaAcercaDe_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
    ) Handles mnuAyudaAcercaDe.Click

  End Sub

  Private Sub btnNuevo_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
    ) Handles btnNuevo.Click

    ArchivoNuevo()

  End Sub

  Private Sub btnAbrir_Click( _
    ByVal sender As System.Object, _
    ByVal e As System.EventArgs _
    ) Handles btnAbrir.Click

    ArchivoAbrir()

  End Sub

  Private Sub btnGuardar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnGuardar.Click

    ArchivoGuardar()

  End Sub

  Private Sub btnCortar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnCortar.Click

    EdicionCortar()

  End Sub

  Private Sub btnCopiar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnCopiar.Click

    EdicionCopiar()

  End Sub

  Private Sub btnPegar_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnPegar.Click

    EdicionPegar()

  End Sub

  Private Sub btnNegrita_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnNegrita.Click

    FuenteNegrita()

  End Sub

  Private Sub btnCursiva_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnCursiva.Click

    FuenteCursiva()

  End Sub

  Private Sub btnSubrayado_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs _
      ) Handles btnSubrayado.Click

    FuenteSubrayado()

  End Sub

End Class
El contenido de la comunidad está disponible bajo CC-BY-SA a menos que se indique lo contrario.