' MINI EDITOR --- 20 de mayo de 2003
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents btCerrar As System.Windows.Forms.Button
Friend WithEvents btNegrita As System.Windows.Forms.Button
Friend WithEvents btCursiva As System.Windows.Forms.Button
Friend WithEvents btSub As System.Windows.Forms.Button
Friend WithEvents cbFont As System.Windows.Forms.ComboBox
Friend WithEvents cbSize As System.Windows.Forms.ComboBox
Friend WithEvents Texto As System.Windows.Forms.TextBox
Friend WithEvents lbFamilia As System.Windows.Forms.Label
Friend WithEvents lbSize As System.Windows.Forms.Label
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Panel2 As System.Windows.Forms.Panel
Friend WithEvents Panel3 As System.Windows.Forms.Panel
Friend WithEvents btUpper As System.Windows.Forms.Button
Friend WithEvents btLower As System.Windows.Forms.Button
Friend WithEvents btSobre As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Texto = New System.Windows.Forms.TextBox
Me.btCerrar = New System.Windows.Forms.Button
Me.btNegrita = New System.Windows.Forms.Button
Me.btCursiva = New System.Windows.Forms.Button
Me.btSub = New System.Windows.Forms.Button
Me.cbFont = New System.Windows.Forms.ComboBox
Me.cbSize = New System.Windows.Forms.ComboBox
Me.lbFamilia = New System.Windows.Forms.Label
Me.lbSize = New System.Windows.Forms.Label
Me.Panel1 = New System.Windows.Forms.Panel
Me.Panel2 = New System.Windows.Forms.Panel
Me.Panel3 = New System.Windows.Forms.Panel
Me.btLower = New System.Windows.Forms.Button
Me.btUpper = New System.Windows.Forms.Button
Me.btSobre = New System.Windows.Forms.Button
Me.Panel3.SuspendLayout()
Me.SuspendLayout()
'
'Texto
'
Me.Texto.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Texto.Location = New System.Drawing.Point(16, 16)
Me.Texto.Multiline = True
Me.Texto.Name = "Texto"
Me.Texto.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.Texto.Size = New System.Drawing.Size(312, 152)
Me.Texto.TabIndex = 0
Me.Texto.Text = "TEXTO DE PRUEBA. Modifica las propiedades de la fuente pulsando en los botones y " & _
"en los cuadros de lista. Puedes añadir o borrar texto. Los cambios se aplican a " & _
"todo el texto del control. Si el tipo o el tamaño de fuente están sin selecciona" & _
"r, el programa no hará nada."
Me.Texto.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'btCerrar
'
Me.btCerrar.BackColor = System.Drawing.SystemColors.Control
Me.btCerrar.Cursor = System.Windows.Forms.Cursors.Hand
Me.btCerrar.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btCerrar.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btCerrar.ForeColor = System.Drawing.Color.Black
Me.btCerrar.Location = New System.Drawing.Point(352, 16)
Me.btCerrar.Name = "btCerrar"
Me.btCerrar.Size = New System.Drawing.Size(112, 48)
Me.btCerrar.TabIndex = 6
Me.btCerrar.Text = "Cerrar"
'
'btNegrita
'
Me.btNegrita.Cursor = System.Windows.Forms.Cursors.Hand
Me.btNegrita.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btNegrita.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btNegrita.Location = New System.Drawing.Point(256, 200)
Me.btNegrita.Name = "btNegrita"
Me.btNegrita.Size = New System.Drawing.Size(64, 24)
Me.btNegrita.TabIndex = 3
Me.btNegrita.Text = "Negrita"
'
'btCursiva
'
Me.btCursiva.Cursor = System.Windows.Forms.Cursors.Hand
Me.btCursiva.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btCursiva.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btCursiva.Location = New System.Drawing.Point(328, 200)
Me.btCursiva.Name = "btCursiva"
Me.btCursiva.Size = New System.Drawing.Size(64, 24)
Me.btCursiva.TabIndex = 4
Me.btCursiva.Text = "Cursiva"
'
'btSub
'
Me.btSub.Cursor = System.Windows.Forms.Cursors.Hand
Me.btSub.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btSub.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btSub.Location = New System.Drawing.Point(400, 200)
Me.btSub.Name = "btSub"
Me.btSub.Size = New System.Drawing.Size(64, 24)
Me.btSub.TabIndex = 5
Me.btSub.Text = "Subrayar"
'
'cbFont
'
Me.cbFont.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cbFont.Location = New System.Drawing.Point(16, 208)
Me.cbFont.MaxDropDownItems = 12
Me.cbFont.Name = "cbFont"
Me.cbFont.Size = New System.Drawing.Size(176, 21)
Me.cbFont.Sorted = True
Me.cbFont.TabIndex = 1
Me.cbFont.TabStop = False
'
'cbSize
'
Me.cbSize.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cbSize.Items.AddRange(New Object() {"8", "10", "12", "14", "18", "24", "48"})
Me.cbSize.Location = New System.Drawing.Point(200, 208)
Me.cbSize.MaxDropDownItems = 7
Me.cbSize.Name = "cbSize"
Me.cbSize.Size = New System.Drawing.Size(48, 21)
Me.cbSize.TabIndex = 2
Me.cbSize.TabStop = False
'
'lbFamilia
'
Me.lbFamilia.AutoSize = True
Me.lbFamilia.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lbFamilia.Location = New System.Drawing.Point(56, 192)
Me.lbFamilia.Name = "lbFamilia"
Me.lbFamilia.Size = New System.Drawing.Size(86, 17)
Me.lbFamilia.TabIndex = 9
Me.lbFamilia.Text = "Tipo de fuente"
Me.lbFamilia.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'lbSize
'
Me.lbSize.AutoSize = True
Me.lbSize.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lbSize.Location = New System.Drawing.Point(200, 192)
Me.lbSize.Name = "lbSize"
Me.lbSize.Size = New System.Drawing.Size(50, 17)
Me.lbSize.TabIndex = 10
Me.lbSize.Text = "Tamaño"
Me.lbSize.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Panel1
'
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel1.Location = New System.Drawing.Point(8, 184)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(464, 56)
Me.Panel1.TabIndex = 8
'
'Panel2
'
Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel2.Location = New System.Drawing.Point(7, 8)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(329, 168)
Me.Panel2.TabIndex = 7
'
'Panel3
'
Me.Panel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel3.Controls.Add(Me.btLower)
Me.Panel3.Controls.Add(Me.btUpper)
Me.Panel3.Controls.Add(Me.btSobre)
Me.Panel3.Location = New System.Drawing.Point(344, 8)
Me.Panel3.Name = "Panel3"
Me.Panel3.Size = New System.Drawing.Size(128, 168)
Me.Panel3.TabIndex = 11
'
'btLower
'
Me.btLower.Cursor = System.Windows.Forms.Cursors.Hand
Me.btLower.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btLower.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btLower.Location = New System.Drawing.Point(8, 104)
Me.btLower.Name = "btLower"
Me.btLower.Size = New System.Drawing.Size(112, 24)
Me.btLower.TabIndex = 1
Me.btLower.Text = "Minúsculas"
'
'btUpper
'
Me.btUpper.Cursor = System.Windows.Forms.Cursors.Hand
Me.btUpper.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btUpper.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btUpper.Location = New System.Drawing.Point(8, 72)
Me.btUpper.Name = "btUpper"
Me.btUpper.Size = New System.Drawing.Size(112, 24)
Me.btUpper.TabIndex = 0
Me.btUpper.Text = "Mayúsculas"
'
'btSobre
'
Me.btSobre.Cursor = System.Windows.Forms.Cursors.Hand
Me.btSobre.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btSobre.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btSobre.Location = New System.Drawing.Point(8, 136)
Me.btSobre.Name = "btSobre"
Me.btSobre.Size = New System.Drawing.Size(112, 24)
Me.btSobre.TabIndex = 2
Me.btSobre.Text = "Sobrerrayar"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(478, 248)
Me.Controls.Add(Me.lbSize)
Me.Controls.Add(Me.lbFamilia)
Me.Controls.Add(Me.cbSize)
Me.Controls.Add(Me.cbFont)
Me.Controls.Add(Me.btSub)
Me.Controls.Add(Me.btCursiva)
Me.Controls.Add(Me.btNegrita)
Me.Controls.Add(Me.btCerrar)
Me.Controls.Add(Me.Texto)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.Panel2)
Me.Controls.Add(Me.Panel3)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "Form1"
Me.Text = "Editor MINI"
Me.Panel3.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim tipo As String ' variable para contener el nombre de la fuente seleccionada
' declarada en el ámbito de la clase para que sea accesible a vatios subprocedimientos
' Salto de línea para usar en los cuadros de diálogo
Dim saltoLinea As Char = Chr(13) & Chr(10)
' Al arrancar el programa
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Posiciones x.y del formulario
Me.Top = 100
Me.Left = 100
' Listar las fuentes del sistema en el combobox cbFont
Dim ff As FontFamily
For Each ff In System.Drawing.FontFamily.Families
cbFont.Items.Add(ff.Name)
Next
' Colocar el cursor al final del texto
Texto.SelectionStart = Texto.Text.Length
Texto.SelectionLength = 0
' Valores iniciales de los combobox cbFont y cbSize
cbFont.SelectedItem = "Verdana"
cbSize.SelectedItem = "10"
End Sub
' Cambiar la selección de los combobox cbFont y cbSize
Private Sub cbFont_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbFont.SelectedIndexChanged, cbSize.SelectedIndexChanged
Try ' para detectar y manipular excepciones (errores del programa)
tipo = CStr(cbFont.SelectedItem) ' tipo equivale a la fuente seleccionada en cbFont
If cbFont.SelectedIndex >= 0 And cbSize.SelectedIndex >= 0 Then ' si está seleccionado algún tipo y tamaño de fuente
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem) ' cambio de fuente o de tamaño
Else ' si falta elegir tipo o tamaño de fuente
Return ' no hacer nada
End If
' capturo las excepciones del tipo System.ArgumentException
Catch ffError As System.ArgumentException
Dim errorMensaje As String ' variable de cadena
errorMensaje = ffError.Message ' que contiene el mensaje con la causa de la excepción
' muestro ese mensaje al usuario
MessageBox.Show("Ha ocurrido el siguiente error: " & saltoLinea & ffError.Message & saltoLinea & "Selecciona otra fuente diferente.", "Error del programa", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Application.Exit() ' cierro el programa
End Try
End Sub
' Pasar a mayúsculas
Private Sub btUpper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btUpper.Click
Texto.Text = Texto.Text.ToUpper ' convertir a mayúsculas
End Sub
' Pasar a minúsculas
Private Sub btLower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLower.Click
Texto.Text = Texto.Text.ToLower 'convertir a minúsculas
End Sub
' Botón de negrita
Private Sub btNegrita_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNegrita.Click
' si está seleccionado algún tipo o tamaño de fuente
Try ' para detectar y manipular excepciones (errores del programa)
If cbSize.SelectedIndex >= 0 And cbFont.SelectedIndex >= 0 Then
If Texto.Font.Bold = False Then ' si el texto NO está en negrita
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Bold) ' poner negrita
Else
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Regular) ' quitar negrita
End If
Else ' si falta elegir tipo o tamaño de fuente
Return ' no hacer nada
End If
' capturo las excepciones del tipo System.ArgumentException
Catch ffError As System.ArgumentException
Dim errorMensaje As String ' variable de cadena
errorMensaje = ffError.Message ' que contiene el mensaje con la causa de la excepción
' muestro ese mensaje al usuario
MessageBox.Show("Ha ocurrido el siguiente error: " & saltoLinea & ffError.Message & saltoLinea & "Selecciona otra fuente o estilo diferente.", "Error del programa", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Application.Exit() ' cierro el programa
End Try
End Sub
' Botón de cursiva
Private Sub btCursiva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCursiva.Click
' si está seleccionado algún tipo o tamaño de fuente
Try ' para detectar y manipular excepciones (errores del programa)
If cbSize.SelectedIndex >= 0 And cbFont.SelectedIndex >= 0 Then
If Texto.Font.Italic = False Then
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Italic) ' poner cursiva
Else
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Regular) ' quitar cursiva
End If
Else ' si falta elegir tipo o tamaño de fuente
Return ' no hacer nada
End If
' capturo las excepciones del tipo System.ArgumentException
Catch ffError As System.ArgumentException
Dim errorMensaje As String ' variable de cadena
errorMensaje = ffError.Message ' que contiene el mensaje con la causa de la excepción
' muestro ese mensaje al usuario
MessageBox.Show("Ha ocurrido el siguiente error: " & saltoLinea & ffError.Message & saltoLinea & "Selecciona otra fuente o estilo diferente.", "Error del programa", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Application.Exit() ' cierro el programa
End Try
End Sub
' Botón de subrayar
Private Sub btSub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSub.Click
' si está seleccionado algún tipo o tamaño de fuente
Try ' para detectar y manipular excepciones (errores del programa)
If cbSize.SelectedIndex >= 0 And cbFont.SelectedIndex >= 0 Then
If Texto.Font.Underline = False Then
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Underline) ' subrayar
Else
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Regular) ' quitar subrayado
End If
Else ' si falta elegir tipo o tamaño de fuente
Return ' no hacer nada
End If
' capturo las excepciones del tipo System.ArgumentException
Catch ffError As System.ArgumentException
Dim errorMensaje As String ' variable de cadena
errorMensaje = ffError.Message ' que contiene el mensaje con la causa de la excepción
' muestro ese mensaje al usuario
MessageBox.Show("Ha ocurrido el siguiente error: " & saltoLinea & ffError.Message & saltoLinea & "Selecciona otra fuente o estilo diferente.", "Error del programa", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Application.Exit() ' cierro el programa
End Try
End Sub
' Botón de sobrerrayar
Private Sub btSobre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btSobre.Click
' si está seleccionado algún tipo o tamaño de fuente
Try ' para detectar y manipular excepciones (errores del programa)
If cbSize.SelectedIndex >= 0 And cbFont.SelectedIndex >= 0 Then
If Texto.Font.Strikeout = False Then
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Strikeout) ' sobrerrayar
Else
Texto.Font = New System.Drawing.Font(tipo, cbSize.SelectedItem, FontStyle.Regular) ' quitar sobrerrayado
End If
Else ' si falta elegir tipo o tamaño de fuente
Return ' no hacer nada
End If
' capturo las excepciones del tipo System.ArgumentException
Catch ffError As System.ArgumentException
Dim errorMensaje As String ' variable de cadena
errorMensaje = ffError.Message ' que contiene el mensaje con la causa de la excepción
' muestro ese mensaje al usuario
MessageBox.Show("Ha ocurrido el siguiente error: " & saltoLinea & ffError.Message & saltoLinea & "Selecciona otra fuente o estilo diferente.", "Error del programa", MessageBoxButtons.OK, MessageBoxIcon.Error)
' Application.Exit() ' cierro el programa
End Try
End Sub
Private Sub btCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCerrar.Click
End ' salir
End Sub
End Class