Science, Tech, Math › Computer Science Changing Font Properties in VB.NET VB6, Windows Forms and WPF. They're all different! Share Flipboard Email Print Computer Science Visual Basic PHP Programming Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming View More By Dan Mabbutt Dan Mabbutt Computer Science Expert B.S., Computer Science, University of Utah Dan Mabbutt is a Visual Basic expert who created training courses for Visual Basic users. He co-authored two books on the subject. Learn about our Editorial Process Updated on February 27, 2019 Bold is "read-only" in VB.NET. This article tells you how to change that. In VB6, it was dead easy to change a font to bold. You simply coded something like Label1.FontBold, but in VB.NET, the Bold property of the Font object for a Label is read-only. So how do you change it? Changing Font Properties in VB.NET With Windows Forms Here's the basic code pattern for Windows Forms. Private Sub BoldCheckbox_CheckedChanged( _ByVal sender As System.Object, _ByVal e As System.EventArgs) _Handles BoldCheckbox.CheckedChangedIf BoldCheckbox.CheckState = CheckState.Checked ThenTextToBeBold.Font = _New Font(TextToBeBold.Font, FontStyle.Bold)ElseTextToBeBold.Font = _New Font(TextToBeBold.Font, FontStyle.Regular)End IfEnd Sub There's a lot more than Label1.FontBold, that's for sure. In .NET, fonts are immutable. That means once they are created they cannot be updated. VB.NET gives you more control than you get with VB6 over what your program is doing, but the cost is that you have to write the code to get that control. VB6 will internally drop one GDI font resource and create a new one. With VB.NET, you have to do it yourself. You can make things a little more global by adding a global declaration at the top of your form: Private fBold As New Font("Arial", FontStyle.Bold)Private fNormal As New Font("Arial", FontStyle.Regular) Then you can code: TextToBeBold.Font = fBold Note that the global declaration now specifies the font family, Arial, rather than simply using the existing font family of one specific control. Using WPF What about WPF? WPF is a graphical subsystem you can use with the .NET Framework to build applications where the user interface is based on an XML language called XAML and the code is separate from the design and is based on a .NET language like Visual Basic. In WPF, Microsoft changed the process yet again. Here's the way you do the same thing in WPF. Private Sub BoldCheckbox_Checked( _ByVal sender As System.Object, _ByVal e As System.Windows.RoutedEventArgs) _Handles BoldCheckbox.CheckedIf BoldCheckbox.IsChecked = True ThenTextToBeBold.FontWeight = FontWeights.BoldElseTextToBeBold.FontWeight = FontWeights.NormalEnd IfEnd Sub The changes are: The CheckBox event is Checked instead of CheckedChangedThe CheckBox property is IsChecked instead of CheckStateThe property value is a Boolean True/False instead of the Enum CheckState. (Windows Forms offers a True/False Checked property in addition to CheckState, but WPF doesn't have both.)FontWeight is a dependency property of the Label instead of FontStyle being the property of the Font object.FontWeights is a NotInheritable class and Bold is a Static value in that class Whew!! Do you think Microsoft actually tried to make it more confusing? Cite this Article Format mla apa chicago Your Citation Mabbutt, Dan. "Changing Font Properties in VB.NET." ThoughtCo, Feb. 16, 2021, thoughtco.com/changing-font-properties-in-vbnet-3424232. Mabbutt, Dan. (2021, February 16). Changing Font Properties in VB.NET. Retrieved from https://www.thoughtco.com/changing-font-properties-in-vbnet-3424232 Mabbutt, Dan. "Changing Font Properties in VB.NET." ThoughtCo. https://www.thoughtco.com/changing-font-properties-in-vbnet-3424232 (accessed March 29, 2023). copy citation Featured Video