Επεξεργασία

Κοινή χρήση μέσω


Font Constructors

Definition

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

Overloads

Font(Font, FontStyle)

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

Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Initializes a new Font using the specified size, style, unit, and character set.

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Initializes a new Font using a specified size, style, unit, and character set.

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)

Initializes a new Font using a specified size, style, unit, and character set.

Font(String, Single, FontStyle, GraphicsUnit)

Initializes a new Font using a specified size, style, and unit.

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Initializes a new Font using a specified size, style, and unit.

Font(String, Single, FontStyle, GraphicsUnit, Byte)

Initializes a new Font using a specified size, style, unit, and character set.

Font(String, Single, FontStyle)

Initializes a new Font using a specified size and style.

Font(FontFamily, Single, GraphicsUnit)

Initializes a new Font using a specified size and unit. Sets the style to Regular.

Font(FontFamily, Single, FontStyle)

Initializes a new Font using a specified size and style.

Font(String, Single)

Initializes a new Font using a specified size.

Font(FontFamily, Single)

Initializes a new Font using a specified size.

Font(String, Single, GraphicsUnit)

Initializes a new Font using a specified size and unit. The style is set to Regular.

Font(Font, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

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

public:
 Font(System::Drawing::Font ^ prototype, System::Drawing::FontStyle newStyle);
public Font (System.Drawing.Font prototype, System.Drawing.FontStyle newStyle);
new System.Drawing.Font : System.Drawing.Font * System.Drawing.FontStyle -> System.Drawing.Font
Public Sub New (prototype As Font, newStyle As FontStyle)

Parameters

prototype
Font

The existing Font from which to create the new Font.

newStyle
FontStyle

The FontStyle to apply to the new Font. Multiple values of the FontStyle enumeration can be combined with the OR operator.

Examples

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.

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 );
   }
}
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);
    }
}
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

Remarks

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.

Applies to

Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using the specified size, style, unit, and character set.

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet, bool gdiVerticalFont);
public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);
new System.Drawing.Font : string * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte * bool -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte, gdiVerticalFont As Boolean)

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a GDI character set to use for this font.

gdiVerticalFont
Boolean

A Boolean value indicating whether the new Font is derived from a GDI vertical font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

See also

Applies to

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, unit, and character set.

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet, bool gdiVerticalFont);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte * bool -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte, gdiVerticalFont As Boolean)

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a

GDI character set to use for this font.

gdiVerticalFont
Boolean

A Boolean value indicating whether the new font is derived from a GDI vertical font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h.

Applies to

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, unit, and character set.

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte)

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a

GDI character set to use for the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null.

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h.

Applies to

Font(String, Single, FontStyle, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, and unit.

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit);
public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : string * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle, unit As GraphicsUnit)

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity or is not a valid number.

Examples

The following code example demonstrates how to use the Font constructor. This example is designed to be used with Windows Forms. To run this example, paste this code into a form that contains a button named Button2, and associate the Button2_Click method with the Click event of the button.


private:
    void Button2_Click(System::Object^ sender,
        System::EventArgs^ e)
    {
        Button2->Font = gcnew System::Drawing::Font
            (FontFamily::GenericMonospace, 12.0F,
            FontStyle::Italic, GraphicsUnit::Pixel);
    }

private void Button2_Click(System.Object sender, System.EventArgs e)
{

    Button2.Font = new Font(FontFamily.GenericMonospace, 12.0F, 
        FontStyle.Italic, GraphicsUnit.Pixel);
}

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

    Button2.Font = New Font(FontFamily.GenericMonospace, 12.0F, _
        FontStyle.Italic, GraphicsUnit.Pixel)

End Sub

Remarks

Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Applies to

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, and unit.

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle, unit As GraphicsUnit)

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null.

Applies to

Font(String, Single, FontStyle, GraphicsUnit, Byte)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size, style, unit, and character set.

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet);
public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet);
new System.Drawing.Font : string * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte)

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

style
FontStyle

The FontStyle of the new font.

unit
GraphicsUnit

The GraphicsUnit of the new font.

gdiCharSet
Byte

A Byte that specifies a GDI character set to use for this font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The gdiCharSet parameter takes a value from the list defined in the Windows SDK header file WinGDI.h. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

See also

Applies to

Font(String, Single, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and style.

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style);
public Font (string familyName, float emSize, System.Drawing.FontStyle style);
new System.Drawing.Font : string * single * System.Drawing.FontStyle -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle)

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size, in points, of the new font.

style
FontStyle

The FontStyle of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Unit property set to Point. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Applies to

Font(FontFamily, Single, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and unit. Sets the style to Regular.

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::GraphicsUnit unit);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, unit As GraphicsUnit)

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

family is null.

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Style property set to FontStyle.Regular.

Applies to

Font(FontFamily, Single, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and style.

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle)

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size, in points, of the new font.

style
FontStyle

The FontStyle of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

family is null.

Examples

The following code example demonstrates how to set the Font property of a button to a new, bold-style Font. This example is designed to be used with a Windows Form that contains a button named Button1. Paste the following code into your form and associate the Button1_Click method with the button's Click event.

private:
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      Button1->Font = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,12.0F,FontStyle::Bold );
   }
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    if (Button1.Font.Style != FontStyle.Bold)
            Button1.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold);
}
 Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    If Not Button1.Font.Style = FontStyle.Bold Then
        Button1.Font = New Font(FontFamily.GenericSansSerif, _
            12.0F, FontStyle.Bold)
    End If
End Sub

Remarks

The resulting font has its Unit property set to Point.

Applies to

Font(String, Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size.

public:
 Font(System::String ^ familyName, float emSize);
public Font (string familyName, float emSize);
new System.Drawing.Font : string * single -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single)

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size, in points, of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity or is not a valid number.

Examples

The following code example demonstrates how to use the Font constructor. This example is designed to be used with a Windows Form and requires a PaintEventArgs e, which is a parameter of the Paint event.

private void ConstructFontWithString(PaintEventArgs e)
{
    Font font1 = new Font("Arial", 20);
    e.Graphics.DrawString("Arial Font", font1, Brushes.Red, new PointF(10, 10));
}
Private Sub ConstructFontWithString(ByVal e As PaintEventArgs)
    Dim font1 As New Font("Arial", 20)
    e.Graphics.DrawString("Arial Font", font1, Brushes.Red, New PointF(10, 10))
End Sub

Remarks

The resulting font has its Style property set to FontStyle.Regular and its Unit property set to GraphicsUnit.Point. Windows Forms applications support TrueType fonts and have limited support for OpenType fonts. If the familyName parameter specifies a font that is not installed on the machine running the application or is not supported, Microsoft Sans Serif will be substituted.

Applies to

Font(FontFamily, Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size.

public:
 Font(System::Drawing::FontFamily ^ family, float emSize);
public Font (System.Drawing.FontFamily family, float emSize);
new System.Drawing.Font : System.Drawing.FontFamily * single -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single)

Parameters

family
FontFamily

The FontFamily of the new Font.

emSize
Single

The em-size, in points, of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Style property set to Regular and its Unit property set to Point.

Applies to

Font(String, Single, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

Initializes a new Font using a specified size and unit. The style is set to Regular.

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::GraphicsUnit unit);
public Font (string familyName, float emSize, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : string * single * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, unit As GraphicsUnit)

Parameters

familyName
String

A string representation of the FontFamily for the new Font.

emSize
Single

The em-size of the new font in the units specified by the unit parameter.

unit
GraphicsUnit

The GraphicsUnit of the new font.

Exceptions

emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.

Remarks

The resulting font has its Style property set to FontStyle.Regular.

Applies to