VB.Net - Wijzig lettertypen, kleuren en stijl van besturingselementen

Intro

Zoals gebruikelijk heeft VB.Net vreemde reacties wanneer het lettertype van een besturingselement wordt gewijzigd, de stijlen worden gereset en ze opnieuw moeten worden gedefinieerd.

Om dit probleem aan te pakken:

De code

 Public Class Form1 Private Sub Form1_Load (ByVal-afzender als System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Byte, L, S als integer Dim FonteSys als FontFamily TextBox1.Text = "Si tu te cognes à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide.; -) (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 Probeer ComboBox1.SelectedIndex = L Catch ex As Exception ComboBox1.SelectedIndex = ComboBox1.Items.Count - 1 End Probeer 'Propriétés de la boite de dialogue couleur' ​​BoiteCouleur.SolidColorOnly = True 'Couleurs unies' BoiteCouleur.AllowFullOpen = True 'Affiche le couleurs personnalisées' BoiteCouleur.FullOpen = True 'Affiche les couleurs personnalisées' BoiteCouleur.Color = Color.Red 'Préselection de la couleur For Each FonteSys In System.Drawing.FontFamily. Families CombPolice.Items.Add (FonteSys.Name) If TextBox1.Font.Name = FonteSys.Name Then L = CombPolice.Ite ms.Count - 1 volgende Probeer CombPolice.SelectedIndex = L Catch ex As Exception ComboBox1.SelectedIndex = 0 End Try End Sub Private Sub ComboBox1_SelectedIndexChanged (ByVal-afzender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim oldFont As Font = TextBox1.Font Dim NewFont As Font = Nieuw lettertype (oldFont.FontFamily, Val (ComboBox1.Text)) TextBox1.Font = newFont ChangeStyle () End Sub Private Sub CheckBox1_CheckedChanged_1 (ByVal-afzender als System.Object, ByVal e As System. EventArgs) Handles CheckBox1.CheckedChanged, _ CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged ChangeStyle () 'Autre syntaxe' Dimstijl als FontStyle = IIf (TextBox1.Font.Style en FontStyle.Bold, TextBox1.Font.Style Xor FontStyle .Bold, TextBox1.Font.Style of FontStyle.Bold) 'TextBox1.Font = Nieuw lettertype (TextBox1.Font, stijl) End Sub Private Sub Button1_Click (ByVal-afzender als System.Object, ByVal e As System.EventArgs) Handles Button1. Klik op Als BoiteCouleur.ShowDialog () = Di alogResult.OK Then TextBox1.ForeColor = BoiteCouleur.Color End If 'Autre syntaxe' TextBox1.ForeColor = Color.FromArgb (& HFF0000) End Sub Private Sub Button2_Click (ByVal-afzender als System.Object, ByVal e As System.EventArgs) Handles Button2. Klik op If BoiteCouleur.ShowDialog () = DialogResult.OK Then TextBox1.BackColor = BoiteCouleur.Color End If End Sub Private Sub CombPolice_SelectedIndexChanged (ByVal-afzender als 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 () Dimstijl als FontStyle = FontStyle.Bold And CheckBox1.Checked Of FontStyle.Italic en CheckBox2.Checked _ Of FontStyle.Underline en CheckBox3.Checked of FontStyle.Strikeout en _ CheckBox4.Checked 'Pas nécessaire à chaque fois. 'TextBox1.Font = Nieuw System.Drawing.Font (CombPolice.Text, CInt (ComboBox1.Text)) TextBox1.Font = Nieuw lettertype (TextBox1.Font, stijl) End Sub End Class 

Download

Download de demo-oplossing

Server 1: hier

Vorige Artikel Volgende Artikel

Top Tips