[Handler(Icon.IHandler)] [TypeConverter(IconConverter)] public class Icon : Image
Represents an icon which allows for multiple sizes and resolutions of an image
Remarks: The formats supported vary by platform, however all platforms do support loading windows .ico format. Using an icon for things like menus, toolbars, etc are preferred so that each platform can use the appropriate sized image. For High DPI/Retina displays (e.g. on OS X), this will allow using a higher resolution image automatically.

Constructors

Icon

#
public Icon(float scale, Bitmap bitmap)
Initializes a new instance of the Icon class with the specified bitmap.
Remarks: This is used when you want to create an icon with a single bitmap frame with the specified logical scale.
scale (float)Logical pixel scale of the specified bitmap.
bitmap (Bitmap)Bitmap for the frame.

Icon

#
public Icon(IEnumerable<IconFrame> frames)
Initializes a new instance of the Icon class with the specified frames.
Remarks: This is used when you want to create an icon with specific bitmap frames at different scales or sizes.
frames (IEnumerable<IconFrame>)Frames for the icon.

Icon

#
public Icon(IHandler handler)
Initializes a new instance of the Icon class with the specified handler

Icon

#
public Icon(params IconFrame[] frames)
Initializes a new instance of the Icon class with the specified frames.
Remarks: This is used when you want to create an icon with specific bitmap frames at different scales or sizes.
frames (params IconFrame[])Frames for the icon.

Icon

#
public Icon(Stream stream)
Initializes a new instance of the Icon class with the contents of the specified stream

Icon

#
public Icon(string fileName)
Intitializes a new instanc of the Icon class with the contents of the specified fileName

Properties

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.

Frames

#
public IEnumerable<IconFrame> Frames { get; }
Gets the definition for each frame in this icon.

Handler

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

Height

public int Height { get; }
Gets the height of the image, in pixels.
inherited fromImage
Remarks: Use Image.Size if you wish to get the width and height at the same time.
The height of the image, in pixels
Image.Size

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.

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

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

Width

public int Width { get; }
Gets the width of the image, in pixels.
inherited fromImage
Remarks: Use Image.Size if you wish to get the width and height at the same time.
The width of the image, in pixels
Image.Size

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

FromResource

#
[MethodImpl(MethodImplOptions.NoInlining)] public static Icon FromResource(string resourceName, Assembly assembly = null)
Loads an icon from an embedded resource of the specified assembly
resourceName (string)Fully qualified name of the resource to load. E.g. "MyProject.SomeFolder.YourFile.extension"
assembly (Assembly = null)Assembly to load the resource from
A new instance of an Icon loaded with the contents of the specified resource

FromResource

#
public static Icon FromResource(string resourceName, Type type)
Loads an icon from a resource in the same assembly as the specified type
resourceName (string)Full name of the resource in the type's assembly E.g. "MyProject.SomeFolder.YourFile.extension"
type (Type)Type of the assembly to get the resource.
The icon instance.

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

GetFrame

#
public IconFrame GetFrame(float scale, Size? fittingSize = null)
Gets the frame with the specified scale that can fit into the fittingSize if specified.
Remarks: This can be used to determine which frame should be used to draw to the screen, based on the desired logical pixel scale and final drawn size of the icon.
scale (float)Logical scale to find for, 1 for normal size, 2 for retina, etc.
fittingSize (Size? = null)Fitting size that the icon will be drawn to, if known.
The frame that is the closest match for the specified scale and fitting size.

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.

OnStyleChanged

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

ToString

public override string ToString()
Gets a string that represents the current object with its ID if specified.
inherited fromWidget
A string value indicating the type and ID (if specified) of this widget.
Object.ToString

WithSize

#
public Icon WithSize(int width, int height)
Gets a copy of this Icon with frames scaled to draw within the specified fitting size.
Remarks: This is useful when you want to draw an Icon at a different size than the default size. Note that the width and height specifies the maxiumum drawing size of the Icon, but will not change the aspect of each frame's bitmap. For example, if an existing frame is 128x128, and you specify 16x32, then the resulting frame will draw at 16x16.
width (int)Maxiumum drawing width for the new icon.
height (int)Maxiumum drawing height for the new icon.
A new icon that will draw within the fitting size.

WithSize

#
public Icon WithSize(Size fittingSize)
Gets a copy of this Icon with frames scaled to draw within the specified fitting size.
Remarks: This is useful when you want to draw an Icon at a different size than the default size. Note that the fittingSize specifies the maxiumum drawing size of the Icon, but will not change the aspect of each frame's bitmap. For example, if an existing frame is 128x128, and you specify 16x32, then the resulting frame will draw at 16x16.
fittingSize (Size)The maximum size to draw the Icon.
A new icon that will draw within the fitting size.

Events