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 styleParameters:
| 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
#Initializes a new instance of the Font class with the specified
typeface and sizeParameters:
| 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
handlerRemarks: Not intended to be used directly, this is used by each platform to pass back a font instance with a specific handler
Parameters:
| 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 styleParameters:
| 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 sizeRemarks: The system fonts are the same fonts that the standard UI of each platform use for particular areas given the SystemFont enumeration.
Parameters:
| 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
#Gets the top y co-ordinate from the baseline to the tallest character ascent
Value: The tallest ascent of the font
Baseline
#Gets the offset of the baseline from the drawing point
Value: The baseline offset from the drawing point
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
#Gets the bottom y co-ordinate from the baseline to the longest character descent
Value: The longest descent of the font
FontDecoration
#Gets the decorations applied to the font
Remarks: Decorations can be applied to any typeface/style of font.
Value: The font decoration.
FontStyle
#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.
IsDisposed
Gets or sets a value indicating whether this Widget has been disposed.
Remarks: When the widget is disposed, it can no longer be used.
Value:
true if this instance has been disposed; otherwise, false.NativeHandle
public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
Value: The native handle.
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object
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.
Example:
// 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;
});Gets the offset of the underline from the baseline
Gets the thickness of the underline
Methods
Dispose
public void Dispose()
Disposes of this widget, supressing the finalizer
Parameters:
| disposing (bool) | True if the caller called Widget.Dispose() manually, false if being called from a finalizer |
Equals
#Overrides: 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.
Parameters:
| 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 |
Returns: A new instance of the Font object
See Also: FontTypeface.FontTypeface(string)
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.
Parameters:
| 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 |
Returns: A new instance of the Font object
See Also: FontTypeface.FontTypeface(Stream)
GetCallback
Gets an instance of an object used to perform callbacks to the widget from handler implementations
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.
Returns: The callback instance to use for this widget
GetHashCode
#Serves as a hash function for a Font object.
Returns: A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.
Overrides: Object.GetHashCode
Initialize
protected void Initialize()
Initializes the widget handler
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
#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.
Parameters:
| text (string) | Text string to measure. |
Returns: The size of the text in logical pixels if drawn using Graphics.DrawText.
See Also: Graphics.MeasureString(Font, string)
inherited fromWidget
ToString
#Gets a string representation of the font object
Returns: String representation of the font object
Overrides: Widget.ToString
Events
inherited fromWidget