Está tudo no título.
Como de hábito VB.Net tem reações estranhas, quando a fonte de um controle é alterada, os estilos são reinicializados, é preciso, então, redefini-los.
Agencie uma forma como o modelo aqui acima.
O código
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Byte, L, S As Integer
Dim FonteSys As FontFamily
TextBox1.Text = "Se tu esbarras com algo e que soa oco, não é obrigatoriamente algo que é vazio.)(Confucius)"
S = TextBox1.Font.Size
For i = 8 To 24 Step 2
ComboBox1.Items.Add(i)
If i = S Then L = ComboBox1.Items.Count - 1
Next
Try
ComboBox1.SelectedIndex = L
Catch ex As Exception
ComboBox1.SelectedIndex = ComboBox1.Items.Count - 1
End Try
'Propriedades da caixa de dialogo cor
'CaixaCor.SolidColorOnly = True 'Cores chapadas
'CaixaCor.AllowFullOpen = True 'Afixa o botão das Cores personalizadas
'CaixaCor.FullOpen = True 'Afixa as Cores personalizadas
'CaixaCor.Color = Color.Red 'Pré seleção da cor
For Each FonteSys In System.Drawing.FontFamily.Families
CombPolice.Items.Add(FonteSys.Name)
If TextBox1.Font.Name = FonteSys.Name Then L = CombPolice.Items.Count - 1
Next
Try
CombPolice.SelectedIndex = L
Catch ex As Exception
ComboBox1.SelectedIndex = 0
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim oldFont As Font = TextBox1.Font
Dim newFont As Font = New Font(oldFont.FontFamily, Val(ComboBox1.Text))
TextBox1.Font = newFont
ChangeStyle()
End Sub
Private Sub CheckBox1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, _
CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged
ChangeStyle()
'Autre syntaxe
'Dim style As FontStyle = IIf(TextBox1.Font.Style And FontStyle.Bold, TextBox1.Font.Style Xor FontStyle.Bold, TextBox1.Font.Style Or FontStyle.Bold)
'TextBox1.Font = New Font(TextBox1.Font, style)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CaixaCor.ShowDialog() = DialogResult.OK Then
TextBox1.ForeColor = CaixaCor.Color
End If
`Outra sintaxe
'TextBox1.ForeColor = Color.FromArgb(&HFF0000)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If CaixaCor.ShowDialog() = DialogResult.OK Then
TextBox1.BackColor = CaixaCor.Color
End If
End Sub
Private Sub CombPolice_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CombPolice.SelectedIndexChanged
If TextBox1.Font.Name <> CombPolice.Text Then
TextBox1.Font = New System.Drawing.Font(CombPolice.Text, CInt(ComboBox1.Text))
ChangeStyle()
End If
End Sub
Sub ChangeStyle()
Dim style As FontStyle = FontStyle.Bold And CheckBox1.Checked Or FontStyle.Italic And CheckBox2.Checked _
Or FontStyle.Underline And CheckBox3.Checked Or FontStyle.Strikeout And _
CheckBox4.Checked
'Pas nécessaire à chaque fois.
'TextBox1.Font = New System.Drawing.Font(CombPolice.Text, CInt(ComboBox1.Text))
TextBox1.Font = New Font(TextBox1.Font, style)
End Sub
End Class
Download
Baixara a solução demo
Serveur 1 :
StyleTexte(2).zip
Tradução feita por Ana Spadari
A ver igualmente
Comunidade de assistência e de conselho.
Artigo original publicado por
lermite222. Tradução feita por
ninha25.