Muy buenas.
Estaba haciendo una práctica y resulta que no logro ver como mantener el estilo subrayado, negrita, o cursiva al cambiar el tamaño de letra, puesto que al parecer se reinician los valores. Creo (pienso) que el new de listboxchanged esta creando lo que es un estilo nuevo y no me lo esta manteniendo.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "HOLA"
TextBox1.TextAlign = HorizontalAlignment.Center
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Font = New Font(TextBox1.Font.Style, ListBox1.SelectedItem)
'CheckBox1.Checked = False
'CheckBox2.Checked = False
'CheckBox3.Checked = False
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
'DESDE TEXTBOX1.FONT ACTUA COMO EL TEXTBOX1.TEXT = TEXTBOX1.TEXT DICIENDO TEXTBOX1.FONT = AL ESTILO QUE CONTENGA + EL NUEVO NEGRITA
If CheckBox1.Checked = False Then TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Bold)
If CheckBox1.Checked = True Then TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Bold)
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked = False Then TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Underline) 'quita el estilo de negrita del texto
If CheckBox2.Checked = True Then TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Underline)
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
If CheckBox3.Checked = False Then TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Italic)
If CheckBox3.Checked = True Then TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Italic) 'cambia a negerita el cuadro de texto
End Sub
End Class
He hecho creo yo que una pequeña chapucilla, no se si habría alguna forma mejor de hacerlo ya que me da la sensación que repito demasiado código.
Esta parte iría en el Private Sub ListBox1_SelectedIndexChanged...
If CheckBox1.Checked = True Then
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Bold)
End If
If CheckBox2.Checked = True Then
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Underline)
End If
If CheckBox3.Checked = True Then
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Italic) 'cambia a negerita el cuadro de texto
End If
Porque no le pasas el estilo anterior.
TextBox1.Font = New Font(TextBox1.SelectedText, 12, TextBox1.Font.Style)
asi camibas el tamaño y mantines el stilo que tengas.
saludos
Gracias !!!, eso mismo estaba buscando, sabía que alguna manera tendría que haber.
Al final he usado lo mismo en vez de 12 de tamaño he usado el listbox.selectdItem que er lo que quería y por alguna razón lo había olvidado por completo.
TextBox1.Font = New Font(TextBox1.SelectedText, ListBox1.SelectedItem, TextBox1.Font.Style)
Solucionado ;)