WHAT'S NEW?
Loading...

Change font style at runtime in Visual Basic.Net


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.

3 comments: Leave Your Comments

  1. Learned a lot of

    new things from your post!Good creation ,thanks for good info .

    Net Online Training Hyderabad

    ReplyDelete
  2. Dafont.com is a site where you can download a ton of free fonts. You can search for a specific typeface, or search by the type of lettering you want, whether it’s serif or sans serif, hand lettered or grunge style. You can also put in your own phrase to see how it looks in a particular font. A lot of these fonts are very decorative and many are handdrawn, so it’s not always the best place to search for body text fonts. Each selection also tells you whether your download is free for personal or commercial use. The download is easy – you get a zip file with the font file inside. Unzip, install, and you’re ready to go.

    ReplyDelete
  3. Dafont.com is a site where you can download a ton of free fonts. You can search for a specific typeface, or search by the type of lettering you want, whether it’s serif or sans serif, hand lettered or grunge style. You can also put in your own phrase to see how it looks in a particular font. A lot of these fonts are very decorative and many are handdrawn, so it’s not always the best place to search for body text fonts. Each selection also tells you whether your download is free for personal or commercial use. The download is easy – you get a zip file with the font file inside. Unzip, install, and you’re ready to go.

    ReplyDelete