Font Construtores

Definição

Inicializa um novo Font que usa o Font e FontStyle existentes.

Sobrecargas

Font(Font, FontStyle)

Inicializa um novo Font que usa a enumeração Font e FontStyle existente especificada.

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

Inicializa uma nova Font usando o tamanho, o estilo, a unidade e o conjunto de caracteres especificados.

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

Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados.

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

Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados.

Font(String, Single, FontStyle, GraphicsUnit)

Inicializa um novo Font usando tamanho, estilo e unidade especificados.

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Inicializa um novo Font usando tamanho, estilo e unidade especificados.

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

Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados.

Font(String, Single, FontStyle)

Inicializa um novo Font usando um tamanho e estilo especificados.

Font(FontFamily, Single, GraphicsUnit)

Inicializa um novo Font usando um tamanho e uma unidade especificados. Define o estilo como Regular.

Font(FontFamily, Single, FontStyle)

Inicializa um novo Font usando um tamanho e estilo especificados.

Font(String, Single)

Inicializa um novo Font usando um tamanho especificado.

Font(FontFamily, Single)

Inicializa um novo Font usando um tamanho especificado.

Font(String, Single, GraphicsUnit)

Inicializa um novo Font usando um tamanho e uma unidade especificados. O estilo está definido como Regular.

Font(Font, FontStyle)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font que usa a enumeração Font e FontStyle existente especificada.

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)

Parâmetros

prototype
Font

O Font existente por meio do qual o novo Font será criado.

newStyle
FontStyle

O FontStyle ao qual o novo Font será aplicado. Vários valores da enumeração FontStyle podem ser combinados com o operador OR.

Exemplos

O exemplo de código a seguir demonstra o Inequality operador, o Font construtor e a Bold propriedade . Este exemplo foi projetado para ser usado com um Windows Form que contém um botão chamado Button2. Cole o código a seguir em seu formulário e associe o Button2_Click método ao evento do Click botão.

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

Comentários

Para aplicativos localizados baseados no .NET Framework 2.0 e versões anteriores, especificar uma fonte para prototype quando essa fonte não tiver sido instalada no computador usado para compilar seu aplicativo fará com que a fonte Microsoft Sans Serif seja usada. Se o aplicativo depender desse comportamento e você precisar recompilar seu aplicativo para o .NET Framework 3.0, especifique a fonte Microsoft Sans Serif para prototype.

Aplica-se a

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

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa uma nova Font usando o tamanho, o estilo, a unidade e o conjunto de caracteres especificados.

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)

Parâmetros

familyName
String

Uma representação de cadeia de caracteres do FontFamily para o novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

style
FontStyle

O FontStyle da nova fonte.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

gdiCharSet
Byte

Um Byte que especifica um conjunto de caracteres GDI a ser usado para essa fonte.

gdiVerticalFont
Boolean

Um valor booliano que indica se o novo Font é derivado de uma fonte vertical GDI.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Comentários

O gdiCharSet parâmetro usa um valor da lista definida no arquivo de cabeçalho SDK do Windows WinGDI.h. Se o familyName parâmetro especificar uma fonte que não está instalada no computador que executa o aplicativo ou não tem suporte, o Microsoft Sans Serif será substituído.

Confira também

Aplica-se a

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

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados.

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)

Parâmetros

family
FontFamily

O FontFamily do novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

style
FontStyle

O FontStyle da nova fonte.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

gdiCharSet
Byte

Um Byte que especifica um

Conjunto de caracteres GDI a ser usado para essa fonte.

gdiVerticalFont
Boolean

Um valor booliano que indica se a nova fonte é derivada de uma fonte vertical GDI.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

family é null

Comentários

O gdiCharSet parâmetro usa um valor da lista definida no arquivo de cabeçalho SDK do Windows WinGDI.h.

Aplica-se a

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

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados.

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)

Parâmetros

family
FontFamily

O FontFamily do novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

style
FontStyle

O FontStyle da nova fonte.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

gdiCharSet
Byte

Um Byte que especifica um

Conjunto de caracteres GDI a ser usado para a nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

family é null.

Comentários

O gdiCharSet parâmetro usa um valor da lista definida no arquivo de cabeçalho SDK do Windows WinGDI.h.

Aplica-se a

Font(String, Single, FontStyle, GraphicsUnit)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando tamanho, estilo e unidade especificados.

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)

Parâmetros

familyName
String

Uma representação de cadeia de caracteres do FontFamily para o novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

style
FontStyle

O FontStyle da nova fonte.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Exemplos

O exemplo de código a seguir demonstra como usar o Font construtor . Este exemplo foi projetado para ser usado com Windows Forms. Para executar este exemplo, cole esse código em um formulário que contém um botão chamado Button2e associe o Button2_Click método ao Click evento do botão.


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

Comentários

Windows Forms aplicativos dão suporte a fontes TrueType e têm suporte limitado para fontes OpenType. Se o familyName parâmetro especificar uma fonte que não está instalada no computador que executa o aplicativo ou não tem suporte, o Microsoft Sans Serif será substituído.

Aplica-se a

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando tamanho, estilo e unidade especificados.

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)

Parâmetros

family
FontFamily

O FontFamily do novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

style
FontStyle

O FontStyle da nova fonte.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

family é null.

Aplica-se a

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

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados.

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)

Parâmetros

familyName
String

Uma representação de cadeia de caracteres do FontFamily para o novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

style
FontStyle

O FontStyle da nova fonte.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

gdiCharSet
Byte

Um Byte que especifica um conjunto de caracteres GDI a ser usado para essa fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Comentários

O gdiCharSet parâmetro usa um valor da lista definida no arquivo de cabeçalho SDK do Windows WinGDI.h. Windows Forms aplicativos dão suporte a fontes TrueType e têm suporte limitado para fontes OpenType. Se o familyName parâmetro especificar uma fonte que não está instalada no computador que executa o aplicativo ou não tem suporte, o Microsoft Sans Serif será substituído.

Confira também

Aplica-se a

Font(String, Single, FontStyle)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando um tamanho e estilo especificados.

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)

Parâmetros

familyName
String

Uma representação de cadeia de caracteres do FontFamily para o novo Font.

emSize
Single

O tamanho em, em pontos, da nova fonte.

style
FontStyle

O FontStyle da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Comentários

A fonte resultante tem sua Unit propriedade definida Pointcomo . Windows Forms aplicativos dão suporte a fontes TrueType e têm suporte limitado para fontes OpenType. Se o familyName parâmetro especificar uma fonte que não está instalada no computador que executa o aplicativo ou não tem suporte, o Microsoft Sans Serif será substituído.

Aplica-se a

Font(FontFamily, Single, GraphicsUnit)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando um tamanho e uma unidade especificados. Define o estilo como 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)

Parâmetros

family
FontFamily

O FontFamily do novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

Exceções

family é null.

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Comentários

A fonte resultante tem sua Style propriedade definida FontStyle.Regularcomo .

Aplica-se a

Font(FontFamily, Single, FontStyle)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando um tamanho e estilo especificados.

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)

Parâmetros

family
FontFamily

O FontFamily do novo Font.

emSize
Single

O tamanho em, em pontos, da nova fonte.

style
FontStyle

O FontStyle da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

family é null.

Exemplos

O exemplo de código a seguir demonstra como definir a Font propriedade de um botão para um novo estilo Fontem negrito . Este exemplo foi projetado para ser usado com um Windows Form que contém um botão chamado Button1. Cole o código a seguir em seu formulário e associe o Button1_Click método ao evento do Click botão.

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

Comentários

A fonte resultante tem sua Unit propriedade definida Pointcomo .

Aplica-se a

Font(String, Single)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando um tamanho especificado.

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)

Parâmetros

familyName
String

Uma representação de cadeia de caracteres do FontFamily para o novo Font.

emSize
Single

O tamanho em, em pontos, da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Exemplos

O exemplo de código a seguir demonstra como usar o Font construtor . Este exemplo foi projetado para ser usado com um Windows Form e requer um PaintEventArgse, que é um parâmetro do Paint evento.

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

Comentários

A fonte resultante tem sua Style propriedade definida FontStyle.Regular como e sua Unit propriedade definida GraphicsUnit.Pointcomo . Windows Forms aplicativos dão suporte a fontes TrueType e têm suporte limitado para fontes OpenType. Se o familyName parâmetro especificar uma fonte que não está instalada no computador que executa o aplicativo ou não tem suporte, o Microsoft Sans Serif será substituído.

Aplica-se a

Font(FontFamily, Single)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando um tamanho especificado.

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)

Parâmetros

family
FontFamily

O FontFamily do novo Font.

emSize
Single

O tamanho em, em pontos, da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Comentários

A fonte resultante tem sua Style propriedade definida Regular como e sua Unit propriedade definida Pointcomo .

Aplica-se a

Font(String, Single, GraphicsUnit)

Origem:
Font.cs
Origem:
Font.cs
Origem:
Font.cs

Inicializa um novo Font usando um tamanho e uma unidade especificados. O estilo está definido como 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)

Parâmetros

familyName
String

Uma representação de cadeia de caracteres do FontFamily para o novo Font.

emSize
Single

O tamanho EM da nova fonte nas unidades especificadas pelo parâmetro unit.

unit
GraphicsUnit

O GraphicsUnit da nova fonte.

Exceções

emSize é menor ou igual a 0, é avaliado como infinito ou não é um número válido.

Comentários

A fonte resultante tem sua Style propriedade definida FontStyle.Regularcomo .

Aplica-se a