WHAT'S NEW?
Loading...
Showing posts with label Change font style in vb.net at runtime. Show all posts
Showing posts with label Change font style in vb.net at runtime. Show all posts

Visual Basic.Net not only provides control properties at design time but also at runtime. Moreover, the user will frequently modify the control properties at runtime where they can change what it looks like. For instance, changing the font style in textbox, more often users didn’t compatible in default font style you made it. Instead, the users can select font style they like. So, in this sample source code can help you to figure out how to use font style at run-time with combo box and textbox in vb.net where the users are free to select their own style. Code is really simple!

 Dim cbselect As Integer = ComboBox1.SelectedIndex

        Select Case cbselect
            Case 0
                TextBox1.Font = New Font(TextBox1.Font, FontStyle.Regular)
            Case 1
                TextBox1.Font = New Font(TextBox1.Font, FontStyle.Bold)
            Case 2
                TextBox1.Font = New Font(TextBox1.Font, FontStyle.Italic)
            Case 3
                TextBox1.Font = New Font(TextBox1.Font, FontStyle.Strikeout)
            Case 4
                TextBox1.Font = New Font(TextBox1.Font, FontStyle.Underline)
        End Select

To try this code, you need Combobox and Textbox. After you drag combobox to your windows form, make sure to edit combobox items and add Regular, Bold, Italic, Strikeout, and Underline in every new line where the users can select font style when the program is running.
Copy and paste this one to your combobox Edit Items or in the properties window, locate the property Items and click (Collection)…

Regular
Bold
Italic
Strikeout
Underline

Once it finished, try to type in textbox and made some selection in combobox to see what will happen. That’s all, hopefully you appreciate it.