[TypeConverter(FontConverter)] [Handler(Font.IHandler)] public class Font : Widget
Defines a format for text
Remarks: A font is typically defined with a specified font family, with a given typeface. Each typeface has certain characteristics that define the variation of the font family, for example Bold, or Italic. You can get a list of FontFamily objects available in the current system using Fonts.AvailableFontFamilies, which can then be used to create an instance of a font.

Constructors

Font

#
public Font(FontFamily family, float size, FontStyle style = FontStyle.None, FontDecoration decoration = FontDecoration.None)
Creates a new instance of the Font class with a specified family, size, and style
family (FontFamily)Family of font to use
size (float)Size of the font, in points
style (FontStyle = FontStyle.None)Style of the font
decoration (FontDecoration = FontDecoration.None)Decorations to apply to the font

Font

#
public Font(FontTypeface typeface, float size, FontDecoration decoration = FontDecoration.None)
Initializes a new instance of the Font class with the specified typeface and size
typeface (FontTypeface)Typeface of the font to create
size (float)Size of the font in points
decoration (FontDecoration = FontDecoration.None)Decorations to apply to the font

Font

#
public Font(IHandler handler)
Initializes a new instance of the Font class with the specified font handler
Remarks: Not intended to be used directly, this is used by each platform to pass back a font instance with a specific handler
handler (Font.IHandler)Handler for the font

Font

#
public Font(string family, float size, FontStyle style = FontStyle.None, FontDecoration decoration = FontDecoration.None)
Creates a new instance of the Font class with a specified family, size, and style
family (string)Family of font to use
size (float)Size of the font, in points
style (FontStyle = FontStyle.None)Style of the font
decoration (FontDecoration = FontDecoration.None)Decorations to apply to the font

Font

#
public Font(SystemFont systemFont, float? size = null, FontDecoration decoration = FontDecoration.None)
Creates a new instance of the Font class with a specified systemFont and optional custom size
Remarks: The system fonts are the same fonts that the standard UI of each platform use for particular areas given the SystemFont enumeration.
systemFont (SystemFont)Type of system font to create
size (float? = null)Optional size of the font, in points. If not specified, the default size of the system font is used
decoration (FontDecoration = FontDecoration.None)Decorations to apply to the font

Properties

Ascent

#
public float Ascent { get; }
Gets the top y co-ordinate from the baseline to the tallest character ascent

Baseline

#
public float Baseline { get; }
Gets the offset of the baseline from the drawing point

Bold

#
public bool Bold { get; }
Gets a value indicating that this font has a bold style

ControlObject

public object ControlObject { get; }
Gets the instance of the platform-specific object
inherited fromWidget
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Widget.Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.

Descent

#
public float Descent { get; }
Gets the bottom y co-ordinate from the baseline to the longest character descent

FamilyName

#
public string FamilyName { get; }
Gets the name of the family of this font

FontDecoration

#
public FontDecoration FontDecoration { get; }
Gets the decorations applied to the font
Remarks: Decorations can be applied to any typeface/style of font.
The font decoration.

FontStyle

#
public FontStyle FontStyle { get; }
Gets the style flags for this font
Remarks: This does not represent all of the style properties of the font. Each Typeface has its own style relative to the font family.

Handler

public object Handler { get; }
Gets the platform-specific handler for this widget
inherited fromWidget

IsDisposed

public bool IsDisposed { get; }
Gets or sets a value indicating whether this Widget has been disposed.
inherited fromWidget
Remarks: When the widget is disposed, it can no longer be used.
true if this instance has been disposed; otherwise, false.

Italic

#
public bool Italic { get; }
Gets a value indicating that this font has an italic style

Leading

#
public float Leading { get; }
Gets the leading space between each line

LineHeight

#
public float LineHeight { get; }
Gets the height of a single line of the font

NativeHandle

public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
inherited fromWidget

Platform

public Platform Platform { get; }
Gets the platform that was used to create the Widget.Handler for this widget
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object

Properties

public PropertyStore Properties { get; }
Gets the dictionary of properties for this widget
inherited fromWidget

Strikethrough

#
public bool Strikethrough { get; }
Gets a value indicating that this font has a strikethrough decoration

Style

public string Style { get; set; }
Gets or sets the style of this widget
inherited fromWidget
Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
// in your UI
var control = new Button { Style = "mystyle" };

// in your platform assembly
using Eto.Mac.Forms.Controls;

Styles.AddHandler<ButtonHandler>("mystyle", handler => {
	// this is where you can use handler.Control to set properties, handle events, etc.
	handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});

Underline

#
public bool Underline { get; }
Gets a value indicating that this font has an underline decoration

UnderlinePosition

#Since v2.12
public float UnderlinePosition { get; }
Gets the offset of the underline from the baseline

UnderlineThickness

#Since v2.12
public float UnderlineThickness { get; }
Gets the thickness of the underline

XHeight

#
public float XHeight { get; }
Gets the height of the lower case 'x' character

Methods

Dispose

protected virtual void Dispose(bool disposing)
Handles the disposal of this widget
inherited fromWidget
disposing (bool)True if the caller called Widget.Dispose() manually, false if being called from a finalizer

Equals

#
public override bool Equals(object obj)
Determines whether the specified object is equal to the current Font.
obj (object)The object to compare with the current Font.
true if the specified object is equal to the current Font; otherwise, false.
Object.Equals

FromFile

#
public static Font FromFile(string fileName, float size, FontDecoration decoration = FontDecoration.None)
Creates a new instance of the Font class with the specified font file on disk.
Remarks: Note that calling this multiple times for the same file may cause additional overhead or unpredictable results, so you should keep a copy of it in memory when you want to use it.
fileName (string)Path to the font file to load
size (float)Size of the font, in points
decoration (FontDecoration = FontDecoration.None)Docorations to apply to the font
A new instance of the Font object

FromStream

#
public static Font FromStream(Stream stream, float size, FontDecoration decoration = FontDecoration.None)
Creates a new instance of the Font class from the specified stream.
Remarks: Note that calling this multiple times for the same stream may cause additional overhead or unpredictable results, so you should keep a copy of it in memory when you want to use it.
stream (Stream)Stream to a font file to load
size (float)Size of the font, in points
decoration (FontDecoration = FontDecoration.None)Decorations to apply to the font
A new instance of the Font object

GetCallback

protected virtual object GetCallback()
Gets an instance of an object used to perform callbacks to the widget from handler implementations
inherited fromWidget
Remarks: The callback should implement the parent class' Widget.ICallback interface so that there only needs to be a single callback for the entire hierarchy. This should return a static instance to avoid having overhead for each instance of your control.
The callback instance to use for this widget

GetHashCode

#
public override int GetHashCode()
Serves as a hash function for a Font object.
A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.

Initialize

protected void Initialize()
Initializes the widget handler
inherited fromWidget
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.

MeasureString

#
public SizeF MeasureString(string text)
Measures the specified string to get its size in logical pixels.
Remarks: This is equivalent to Graphics.MeasureString(Font, string). When you have a Graphics object, it is recommended to use that to measure the string if available, as it may be more efficient and take into account the current graphics state.
text (string)Text string to measure.
The size of the text in logical pixels if drawn using Graphics.DrawText.

OnStyleChanged

protected virtual void OnStyleChanged(EventArgs e)
Handles when the Widget.Style is changed.
inherited fromWidget

ToString

#
public override string ToString()
Gets a string representation of the font object

Events