Font Classe
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Define um formato específico para texto, incluindo os atributos de estilo, tamanho e face da fonte. Essa classe não pode ser herdada.
public ref class Font sealed : MarshalByRefObject, ICloneable, IDisposable, System::Runtime::Serialization::ISerializable
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter("System.Drawing.FontConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))]
[System.Serializable]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Font : MarshalByRefObject, ICloneable, IDisposable, System.Runtime.Serialization.ISerializable
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
[<System.ComponentModel.TypeConverter("System.Drawing.FontConverter, System.Windows.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))>]
[<System.Serializable>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface IDisposable
interface ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter))>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Font = class
inherit MarshalByRefObject
interface ICloneable
interface ISerializable
interface IDisposable
Public NotInheritable Class Font
Inherits MarshalByRefObject
Implements ICloneable, IDisposable, ISerializable
- Herança
- Atributos
- Implementações
O exemplo de código a seguir demonstra como usar o Font construtor e as Sizepropriedades , SizeInPointse Unit . Este exemplo foi projetado para ser usado com um Formulário do Windows que contém um ComboBox nome ComboBox1
que é preenchido com as cadeias de caracteres "Maior" e "Menor" e um Label chamado Label1
. Cole o código a seguir no formulário e associe o ComboBox1_SelectedIndexChanged
método ao SelectedIndexChanged evento do ComboBox controle.
private:
void ComboBox1_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e)
{
// Cast the sender object back to a ComboBox.
ComboBox^ ComboBox1 = (ComboBox^) sender;
// Retrieve the selected item.
String^ selectedString = (String^) ComboBox1->SelectedItem;
// Convert it to lowercase.
selectedString = selectedString->ToLower();
// Declare the current size.
float currentSize;
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
if (selectedString == "bigger")
{
currentSize = Label1->Font->Size;
currentSize += 2.0F;
Label1->Font =gcnew System::Drawing::Font(Label1->Font->Name,
currentSize, Label1->Font->Style, Label1->Font->Unit);
}
// If Smaller is selected, get the current size, in
// points, and decrease it by 2. Reset the font with
// the new size in points.
if (selectedString == "smaller")
{
currentSize = Label1->Font->Size;
currentSize -= 2.0F;
Label1->Font = gcnew System::Drawing::Font(Label1->Font->Name,
currentSize, Label1->Font->Style);
}
}
private void ComboBox1_SelectedIndexChanged(System.Object sender,
System.EventArgs e)
{
// Cast the sender object back to a ComboBox.
ComboBox ComboBox1 = (ComboBox) sender;
// Retrieve the selected item.
string selectedString = (string) ComboBox1.SelectedItem;
// Convert it to lowercase.
selectedString = selectedString.ToLower();
// Declare the current size.
float currentSize;
// Switch on the selected item.
switch(selectedString)
{
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
case "bigger":
currentSize = Label1.Font.Size;
currentSize += 2.0F;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style, Label1.Font.Unit);
// If Smaller is selected, get the current size, in points,
// and decrease it by 1. Reset the font with the new size
// in points.
break;
case "smaller":
currentSize = Label1.Font.SizeInPoints;
currentSize -= 1;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style);
break;
}
}
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
' Cast the sender object back to a ComboBox.
Dim ComboBox1 As ComboBox = CType(sender, ComboBox)
' Retrieve the selected item.
Dim selectedString As String = CType(ComboBox1.SelectedItem, String)
' Convert it to lowercase.
selectedString = selectedString.ToLower()
' Declare the current size.
Dim currentSize As Single
' Switch on the selected item.
Select Case selectedString
' If Bigger is selected, get the current size from the
' Size property and increase it. Reset the font to the
' new size, using the current unit.
Case "bigger"
currentSize = Label1.Font.Size
currentSize += 2.0F
Label1.Font = New Font(Label1.Font.Name, currentSize, _
Label1.Font.Style, Label1.Font.Unit)
' If Smaller is selected, get the current size, in points,
' and decrease it by 1. Reset the font with the new size
' in points.
Case "smaller"
currentSize = Label1.Font.SizeInPoints
currentSize -= 1
Label1.Font = New Font(Label1.Font.Name, currentSize, _
Label1.Font.Style)
End Select
End Sub
Para obter mais informações sobre como construir fontes, consulte Como construir fontes e famílias de fontes. Windows Forms aplicativos dão suporte a fontes TrueType e têm suporte limitado para fontes OpenType. Se você tentar usar uma fonte sem suporte ou a fonte não estiver instalada no computador que está executando o aplicativo, a fonte Microsoft Sans Serif será substituída.
Nota
No .NET 6 e versões posteriores, o pacote System.Drawing.Common, que inclui esse tipo, só tem suporte em sistemas operacionais Windows. O uso desse tipo em aplicativos multiplataforma causa avisos de tempo de compilação e exceções em tempo de execução. Para obter mais informações, consulte System.Drawing.Common com suporte apenas no Windows.
Font(Font, Font |
Inicializa um novo Font que usa a enumeração Font e FontStyle existente especificada. |
Font(Font |
Inicializa um novo Font usando um tamanho especificado. |
Font(Font |
Inicializa um novo Font usando um tamanho e estilo especificados. |
Font(Font |
Inicializa um novo Font usando tamanho, estilo e unidade especificados. |
Font(Font |
Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados. |
Font(Font |
Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados. |
Font(Font |
Inicializa um novo Font usando um tamanho e uma unidade especificados. Define o estilo como Regular. |
Font(String, Single) |
Inicializa um novo Font usando um tamanho especificado. |
Font(String, Single, Font |
Inicializa um novo Font usando um tamanho e estilo especificados. |
Font(String, Single, Font |
Inicializa um novo Font usando tamanho, estilo e unidade especificados. |
Font(String, Single, Font |
Inicializa uma nova Font usando um tamanho, um estilo, uma unidade e um conjunto de caracteres especificados. |
Font(String, Single, Font |
Inicializa uma nova Font usando o tamanho, o estilo, a unidade e o conjunto de caracteres especificados. |
Font(String, Single, Graphics |
Inicializa um novo Font usando um tamanho e uma unidade especificados. O estilo está definido como Regular. |
Bold |
Obtém um valor que indica se este Font está em negrito. |
Font |
Obtém o FontFamily associado a este Font. |
Gdi |
Obtém um valor de byte que especifica o conjunto de caracteres GDI usado por esse Font. |
Gdi |
Obtém um valor booliano que indica se esta Font é derivada de uma fonte vertical GDI. |
Height |
O espaçamento entre linhas dessa fonte. |
Is |
Obtém ou define um valor que indica se a fonte é um membro de SystemFonts. |
Italic |
Obtém um valor que indica se esta fonte tem o estilo itálico aplicado. |
Name |
Obtém o nome de face desse Font. |
Original |
Obtém o nome da fonte especificado originalmente. |
Size |
Obtém o tamanho EM deste Font medido nas unidades especificadas pela propriedade Unit. |
Size |
Obtém o tamanho EM, em pontos, desse Font. |
Strikeout |
Obtém um valor que indica se este Font especifica uma linha horizontal através da fonte. |
Style |
Obtém informações de estilo para este Font. |
System |
Obtém o nome da fonte do sistema se a propriedade IsSystemFont retorna |
Underline |
Obtém um valor que indica se este Font está sublinhado. |
Unit |
Obtém a unidade de medida deste Font. |
Clone() |
Cria uma cópia exata deste Font. |
Create |
Cria um objeto que contém todas as informações relevantes necessárias para gerar um proxy usado para se comunicar com um objeto remoto. (Herdado de MarshalByRefObject) |
Dispose() |
Libera todos os recursos usados por este Font. |
Equals(Object) |
Indica se o objeto especificado é um Font e tem os mesmos valores de propriedade FontFamily, GdiVerticalFont, GdiCharSet, Style, Size e Unit que esse Font. |
Finalize() |
Permite que um objeto tente liberar recursos e executar outras operações de limpeza antes de ser recuperado pela coleta de lixo. |
From |
Cria um Font do identificador do Windows especificado para um contexto de dispositivo. |
From |
Cria um Font com base no identificador especificado do Windows. |
From |
Define um formato específico para texto, incluindo os atributos de estilo, tamanho e face da fonte. Essa classe não pode ser herdada. |
From |
Define um formato específico para texto, incluindo os atributos de estilo, tamanho e face da fonte. Essa classe não pode ser herdada. |
From |
Cria um Font com base na estrutura de fonte lógica GDI especificada ( |
From |
Cria um Font com base na estrutura de fonte lógica GDI especificada ( |
Get |
Obtém o código hash deste Font. |
Get |
Retorna o espaçamento entre linhas, em pixels, dessa fonte. |
Get |
Retorna o espaçamento entre linhas, na unidade atual de um Graphics especificado, dessa fonte. |
Get |
Retorna a altura, em pixels, deste Font quando desenhado em um dispositivo com a resolução vertical especificada. |
Get |
Obsoleto.
Recupera o objeto de serviço de tempo de vida atual que controla a política de ciclo de vida para esta instância. (Herdado de MarshalByRefObject) |
Get |
Obtém o Type da instância atual. (Herdado de Object) |
Initialize |
Obsoleto.
Obtém um objeto de serviço de tempo de vida para controlar a política de tempo de vida para essa instância. (Herdado de MarshalByRefObject) |
Memberwise |
Cria uma cópia superficial do Object atual. (Herdado de Object) |
Memberwise |
Cria uma cópia superficial do objeto MarshalByRefObject atual. (Herdado de MarshalByRefObject) |
To |
Retorna um identificador para esta Font. |
To |
Define um formato específico para texto, incluindo os atributos de estilo, tamanho e face da fonte. Essa classe não pode ser herdada. |
To |
Define um formato específico para texto, incluindo os atributos de estilo, tamanho e face da fonte. Essa classe não pode ser herdada. |
To |
Cria uma estrutura de fonte lógica GDI ( |
To |
Cria uma estrutura de fonte lógica GDI ( |
To |
Retorna uma representação de cadeia de caracteres legível por humanos deste Font. |
ISerializable. |
Popula um SerializationInfo com os dados necessários para serializar o objeto de destino. |
Produto | Versões |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: