예제 #1
0
        private void ArchivoAbrirDoc(FormDocumento FormHijo)
        {
            // Mostrar el diálogo Abrir
            OpenFileDialog DlgAbrir = new OpenFileDialog();

            DlgAbrir.Filter = "ficheros txt (*.txt)|*.txt|ficheros rtf (*.rtf)|*.rtf";
            if (DlgAbrir.ShowDialog() == DialogResult.OK)
            {
                // Obtener el nombre del fichero
                string ruta = DlgAbrir.FileName;
                // Obtener el formato del fichero
                RichTextBoxStreamType formato = RichTextBoxStreamType.PlainText;
                if (DlgAbrir.FilterIndex == 2)
                {
                    formato = RichTextBoxStreamType.RichText;
                }
                // Cargar el fichero
                FormHijo.rtbText.LoadFile(ruta, formato);
                // Mostrar el nombre del fichero en la barra de título
                FormHijo.Text = ruta.Substring(ruta.LastIndexOf("\\") + 1);
                // Mostrar la ruta del fichero en la barra de estado
                this.etbarestPpal.Text = ruta;
                // Aún no ha sido modificado
                FormHijo.rtbText.Modified = false;
            }
        }
예제 #2
0
        private void ArchivoImprimir_Click(object sender, EventArgs e)
        {
            // Formulario padre
            FormMDI formPadre = (FormMDI)this.MdiParent;

            // Formulario hijo activo
            FormDocumento FormHijo = this;

            if (FormHijo == null)
            {
                return;
            }

            // Se supone que durante el diseño se asignó a la propiedad Document
            // de PrintDialog1 el objeto PrintDocument utilizado para imprimir.

            // Permitir al usuario elegir el rango de páginas a imprimir.
            PrintDialog1.AllowSomePages = true;
            if (PrintDialog1.ShowDialog() == DialogResult.OK)
            {
                // Si se pulsó el botón "Aceptar" (OK), entonces imprimir.
                string texto = FormHijo.rtbText.Text;
                char[] seps  = { '\n', '\r' }; // LF y CR
                línea = texto.Split(seps);     //líneas de texto que hay que imprimir
                totalLineasImpresas = 0;
                PrintDocument1.Print();        //invoca a ImprimirDoc_PrintPage
            }
        }
예제 #3
0
        private void FormDocumento_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Formulario hijo activo
            FormDocumento FormHijo = this;

            if (FormHijo == null)
            {
                return;
            }

            // Si el texto cambió...
            if (FormHijo.rtbText.Modified)
            {
                //Preguntar al usuario si quiere guardar el documento
                DialogResult respuesta;
                respuesta = MessageBox.Show("¿Desea guardar los cambios efectuados en " +
                                            this.Text + "?", "Editor MDI", MessageBoxButtons.YesNoCancel);
                if (respuesta == DialogResult.Yes)
                {
                    btbarGuardar.PerformClick();
                }
                else if (respuesta == DialogResult.No)
                {
                    e.Cancel = false;
                }
                else // cancelar
                {
                    e.Cancel = true; // evento cancelado
                }
            }
        }
예제 #4
0
        private void ArchivoGuardar_Click(object sender, EventArgs e)
        {
            // Formulario padre
            FormMDI formPadre = (FormMDI)this.MdiParent;

            // Formulario hijo activo
            FormDocumento FormHijo = this;

            if (FormHijo == null)
            {
                return;
            }

            // Si el texto cambió...
            if (FormHijo.rtbText.Modified)
            {
                // Obtener la ruta actual del fichero
                string ruta = formPadre.etbarestPpal.Text;
                // Obtener el formato actual del fichero
                RichTextBoxStreamType formato = RichTextBoxStreamType.PlainText;
                if (ruta.EndsWith("rtf"))
                {
                    formato = RichTextBoxStreamType.RichText;
                }

                if (FormHijo.Text.StartsWith("Documento"))
                {
                    // Mostrar el diálogo Guardar
                    SaveFileDialog DlgGuardar = new SaveFileDialog();
                    DlgGuardar.Filter =
                        "ficheros txt (*.txt)|*.txt|ficheros rtf (*.rtf)|*.rtf";

                    if (DlgGuardar.ShowDialog() == DialogResult.OK)
                    {
                        // Obtener el nombre del fichero
                        ruta = DlgGuardar.FileName;
                        // Obtener el formato del fichero
                        if (DlgGuardar.FilterIndex == 1)
                        {
                            formato = RichTextBoxStreamType.PlainText;
                        }
                        else if (DlgGuardar.FilterIndex == 2)
                        {
                            formato = RichTextBoxStreamType.RichText;
                        }
                    }
                }

                // Guardar el fichero
                FormHijo.rtbText.SaveFile(ruta, formato);
                // Mostrar el nombre del fichero en la barra de título
                FormHijo.Text = ruta.Substring(ruta.LastIndexOf("\\") + 1);
                // Mostrar la ruta del fichero en la barra de estado
                formPadre.etbarestPpal.Text = ruta;
                // Fichero no modificado
                FormHijo.rtbText.Modified = false;
            }
        }
예제 #5
0
        private void EdicionRehacer_Click(object sender, EventArgs e)
        {
            FormDocumento FormHijo = this;

            // Verificar si la última operación puede rehacerse
            if (FormHijo.rtbText.CanRedo == true)
            {
                // Rehacer la última operación
                FormHijo.rtbText.Redo();
            }
        }
예제 #6
0
        private void EdicionCopiar_Click(object sender, EventArgs e)
        {
            FormDocumento FormHijo = this;

            // Verificar si hay texto seleccionado
            if (FormHijo.rtbText.SelectedText != "")
            {
                // Copiar el texto seleccionado y ponerlo en la papelera
                FormHijo.rtbText.Copy();
            }
        }
예제 #7
0
        private void ArchivoNuevo_Click(object sender, EventArgs e)
        {
            FormDocumento NuevoFormHijo;

            //Crear un nuevo formulario hijo
            NuevoFormHijo = new FormDocumento();
            //Título del formulario hijo
            NuevoFormHijo.Text = "Documento " + MdiChildren.Length.ToString();
            //Establecer el formulario padre del hijo
            NuevoFormHijo.MdiParent = this;
            //Mostrar el formulario hijo
            NuevoFormHijo.Show();
        }
예제 #8
0
        private void FormMDI_MdiChildActivate(object sender, EventArgs e)
        {
            // Eliminar cualquier fusión previa
            ToolStripManager.RevertMerge(this.BarraDeHerraMdiPadre);
            // Ventana hija activa
            FormDocumento vHijaAc = (FormDocumento)this.ActiveMdiChild;

            // Realizar la fusión si hay una ventana hija activa
            if (vHijaAc != null)
            {
                ToolStripManager.Merge(vHijaAc.BarraDeHerraMdiHila,
                                       this.BarraDeHerraMdiPadre);
            }
        }
예제 #9
0
        private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Formulario padre
            FormMDI formPadre = (FormMDI)this.MdiParent;

            // Formulario hijo activo
            FormDocumento FormHijo = this;

            // Insertar aquí el código para procesar la página.

            float lineasPorPag;
            float pos_Y;
            float margenIzq = e.MarginBounds.Left;
            float margenSup = e.MarginBounds.Top;

            // Calcular el número de líneas por página
            Font  fuente     = FormHijo.rtbText.Font;
            float altoFuente = fuente.GetHeight(e.Graphics);

            lineasPorPag = e.MarginBounds.Height / altoFuente;

            // Contador de las líneas impresas en una página
            int lineasImpresasPorPag = 0;

            // Imprimir cada una de las líneas
            while (totalLineasImpresas < línea.Length && lineasImpresasPorPag < lineasPorPag)
            {
                pos_Y = margenSup + (lineasImpresasPorPag * altoFuente);
                e.Graphics.DrawString(línea[totalLineasImpresas], fuente, Brushes.Black, margenIzq, pos_Y, new StringFormat());
                lineasImpresasPorPag += 1;
                totalLineasImpresas  += 1;
            }

            // Si quedan líneas por imprimir, siguiente página
            if (totalLineasImpresas < línea.Length)
            {
                e.HasMorePages = true; // se invoca de nuevo a ImprimirDoc_PrintPage
            }
            else
            {
                e.HasMorePages = false; // finaliza la impresión
            }
        }
예제 #10
0
        private void EdicionPegar_Click(object sender, EventArgs e)
        {
            FormDocumento FormHijo = this;

            // Verificar si hay texto en la papelera para pegar
            if ((Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) == true)
            {
                // Verificar si hay texto seleccionado
                if (FormHijo.rtbText.SelectionLength > 0)
                {
                    // Preguntar al usuario si quiere sobreescribir el texto seleccionado
                    if (MessageBox.Show("¿Quiere sobreescribir la selección?", "Pegar", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        // Mover el punto de inserción después de la selección y pegar
                        FormHijo.rtbText.SelectionStart = FormHijo.rtbText.SelectionStart + FormHijo.rtbText.SelectionLength;
                    }
                }
                // Pegar el contenido de la papelera
                FormHijo.rtbText.Paste();
            }
        }
예제 #11
0
        private void ArchivoAbrir_Click(object sender, EventArgs e)
        {
            // Formulario hijo activo
            FormDocumento FormHijo = (FormDocumento)ActiveMdiChild;

            // Si no hay ningún formulario hijo creado, crear uno
            // ejecutando el método ArchivoNuevo_Click
            if (FormHijo == null)
            {
                ArchivoNuevo.PerformClick();
                FormHijo = (FormDocumento)ActiveMdiChild;
            }

            // Mostrar el diálogo Abrir
            OpenFileDialog DlgAbrir = new OpenFileDialog();

            DlgAbrir.Filter = "ficheros txt (*.txt)|*.txt|ficheros rtf (*.rtf)|*.rtf";
            if (DlgAbrir.ShowDialog() == DialogResult.OK)
            {
                // Obtener el nombre del fichero
                string ruta = DlgAbrir.FileName;
                // Obtener el formato del fichero
                RichTextBoxStreamType formato = RichTextBoxStreamType.PlainText;
                if (DlgAbrir.FilterIndex == 2)
                {
                    formato = RichTextBoxStreamType.RichText;
                }
                // Cargar el fichero
                FormHijo.rtbText.LoadFile(ruta, formato);
                // Mostrar el nombre del fichero en la barra de título
                FormHijo.Text = ruta.Substring(ruta.LastIndexOf("\\") + 1);
                // Mostrar la ruta del fichero en la barra de estado
                this.etbarestPpal.Text = ruta;
                // Aún no ha sido modificado
                FormHijo.rtbText.Modified = false;
            }
        }
예제 #12
0
        private void ArchivoAbrir_Click(object sender, EventArgs e)
        {
            if (this.ActiveMdiChild == null)
            {
                MessageBox.Show("Cree primero un nuevo documento");
                return;
            }
            if (this.ActiveMdiChild.GetType().Equals(Type.GetType("EditorMDI.FormDocumento")))
            {
                // Formulario hijo activo
                FormDocumento FormHijo = (FormDocumento)ActiveMdiChild;

                // Si no hay ningún formulario hijo creado, crear uno
                // ejecutando el método ArchivoNuevo_Click
                if (FormHijo == null)
                {
                    ArchivoNuevo.PerformClick();
                    FormHijo = (FormDocumento)ActiveMdiChild;
                }
                ArchivoAbrirDoc(FormHijo);
            }
            if (this.ActiveMdiChild.GetType().Equals(Type.GetType("EditorMDI.FormDocumento2")))
            {
                // Formulario hijo activo
                FormDocumento2 FormHijo = (FormDocumento2)ActiveMdiChild;

                // Si no hay ningún formulario hijo creado, crear uno
                // ejecutando el método ArchivoNuevo_Click
                if (FormHijo == null)
                {
                    ArchivoNuevo.PerformClick();
                    FormHijo = (FormDocumento2)ActiveMdiChild;
                }
                ArchivoAbrirDoc2(FormHijo);
            }
        }