Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Font Class
Font Constructor
 Font Constructor (Font, FontStyle)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Font Constructor (Font, FontStyle)

Initializes a new Font that uses the specified existing Font and FontStyle enumeration.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)
Visual Basic (Declaration)
Public Sub New ( _
    prototype As Font, _
    newStyle As FontStyle _
)
Visual Basic (Usage)
Dim prototype As Font
Dim newStyle As FontStyle

Dim instance As New Font(prototype, _
    newStyle)
C#
public Font(
    Font prototype,
    FontStyle newStyle
)
Visual C++
public:
Font(
    Font^ prototype, 
    FontStyle newStyle
)
JScript
public function Font(
    prototype : Font, 
    newStyle : FontStyle
)

Parameters

prototype
Type: System.Drawing..::.Font
The existing Font from which to create the new Font.
newStyle
Type: System.Drawing..::.FontStyle
The FontStyle to apply to the new Font. Multiple values of the FontStyle enumeration can be combined with the OR operator.

For localized applications that are based on the .NET Framework 2.0 and earlier releases, specifying a font for prototype when that font has not been installed on the computer that is used to build your application will cause the Microsoft Sans Serif font to be used instead. If your application depends on this behavior and you must recompile your application for the .NET Framework 3.0, you should specify the Microsoft Sans Serif font for prototype.

The following code example demonstrates the Inequality operator, the Font constructor, and the Bold property. This example is designed to be used with a Windows Form that contains a button named Button2. Paste the following code into your form and associate the Button2_Click method with the button's Click event.

Visual Basic
Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click

    If (Color.op_Inequality(Me.BackColor, SystemColors.ControlDark)) Then
        Me.BackColor = SystemColors.ControlDark
    End If
    If Not (Me.Font.Bold) Then
        Me.Font = New Font(Me.Font, FontStyle.Bold)
    End If
End Sub
C#
private void Button2_Click(System.Object sender, System.EventArgs e)
{

    if (this.BackColor != SystemColors.ControlDark)
    {
        this.BackColor = SystemColors.ControlDark;
    }
    if (!(this.Font.Bold))
    {
        this.Font = new Font(this.Font, FontStyle.Bold);
    }
}
Visual C++
void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if ( this->BackColor != SystemColors::ControlDark )
   {
      this->BackColor = SystemColors::ControlDark;
   }

   if (  !(this->Font->Bold) )
   {
      this->Font = gcnew System::Drawing::Font( this->Font,FontStyle::Bold );
   }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker