📜  c# font bold set - C# (1)

📅  最后修改于: 2023-12-03 14:59:40.032000             🧑  作者: Mango

C# Font Bold Set

In C#, font settings can be applied to text in various ways. One way is to set the font style to bold. This can be done using the FontStyle.Bold property of the Font class. In this article, we will explore how to set font to bold in C#.

Setting Font to Bold in C#

To set font to bold in C#, we can create a new instance of Font class and set its Style property to FontStyle.Bold. Here is an example:

Font font = new Font("Arial", 12, FontStyle.Bold);

In the above example, we have created a new font with the following properties:

  • Font family: Arial
  • Font size: 12pt
  • Font style: Bold
Applying Bold Font to Text

Once we have created a font with bold style, we can apply it to text in various ways. Here are some examples:

WinForms Label Control
label1.Font = new Font("Arial", 12, FontStyle.Bold);

In WinForms label control, we can set the font to bold using the Font property.

WPF TextBlock Control
<TextBlock FontSize="12" FontWeight="Bold">Hello World!</TextBlock>

In WPF TextBlock control, we can set the font to bold using the FontWeight property.

Console Application
Console.WriteLine("Hello World!", font);

In a console application, we can set the font to bold using the Console.WriteLine method and passing the Font object as a parameter.

Conclusion

Setting font to bold in C# is a simple task. We can create a new instance of Font class and set its Style property to FontStyle.Bold. Then, we can apply the bold font to text in WinForms, WPF, or a console application.