skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • NEW: Design Kits for Figma
    • Online Training
    • Document Processing Library
    • Embedded Reporting for web and desktop
    Web
    Kendo UI UI for jQuery UI for Angular UI for React UI for Vue UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX UI for Silverlight UI for PHP UI for JSP
    Mobile
    UI for .NET MAUI UI for Xamarin
    Document Management
    Telerik Document Processing
    Desktop
    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF UI for UWP
    Reporting & Mocking
    Telerik Reporting Telerik Report Server Telerik JustMock
    Automated Testing
    Test Studio Test Studio Dev Edition
    CMS
    Sitefinity
    UI/UX Tools
    ThemeBuilder Design System Kit
    Debugging
    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Jam FiddlerCap FiddlerCore
    Extended Reality
    UI for Unity XR
    Free Tools
    JustAssembly JustDecompile VB.NET to C# Converter Testing Framework
    View all products
  • Overview
  • Demos
    • What's New
    • Roadmap
    • Release History
  • Docs & Support
  • Pricing
  • Search
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now
Search all

Struct Unit

A structure representing a unit of measure.

Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
Namespace: Telerik.Reporting.Drawing
Assembly: Telerik.Reporting.dll

Syntax

public struct Unit : IComparable, IComparable<Unit>

Constructors

Unit(Double)

Creates a new instance of the Unit structure from the specified device-independent pixels. The Unit's type is DefaultType

Declaration
public Unit(double dips)
Parameters
System.Double dips

A double value specifying the magnitude of the Unit in device-independent pixels.

Unit(Double, UnitType)

Initializes a new instance of the Unit structure with the specified value and type.

Declaration
public Unit(double value, UnitType type)
Parameters
System.Double value

A double value representing the magnitude of the Unit.

UnitType type

A UnitType specifying the type of the Unit.

Unit(String)

Initializes a new instance of the Unit structure from the specified string value.

Declaration
public Unit(string value)
Parameters
System.String value

A string value representing the magnitude and type of the Unit.

Remarks

Parameters passed to this constructor should be of the form "2px", "3.4in", "4cm", "2mm", "12.5pt", "4pc", etc. For more information on string representations of units see UnitType.

Unit(String, CultureInfo)

Initializes a new instance of the Unit structure from the specified string value and using the specified System.Globalization.CultureInfo.

Declaration
public Unit(string value, CultureInfo culture)
Parameters
System.String value

A string value representing the magnitude and type of the Unit.

System.Globalization.CultureInfo culture

A System.Globalization.CultureInfo. If a null reference (Nothing in Visual Basic) is passed, the current culture is assumed.

Remarks

The culture parameters is used to parse the string value.

Unit(String, CultureInfo, UnitType)

Initializes a new instance of the Unit structure from the specified string value, culture, and type.

Declaration
public Unit(string value, CultureInfo culture, UnitType type)
Parameters
System.String value

A string value representing the magnitude of the Unit.

System.Globalization.CultureInfo culture

A System.Globalization.CultureInfo. If a null reference (Nothing in Visual Basic) is passed, the current culture is assumed.

UnitType type

A UnitType specifying the type of the Unit.

Fields

Empty

Initializes a new instance of the Unit structure.

Declaration
public static readonly Unit Empty
Field Value
Unit

Zero

Initializes a new instance of the Unit structure equal to zero.

Declaration
public static readonly Unit Zero
Field Value
Unit

Properties

DefaultType

Gets or sets a UnitType representing the default units of measure for a Report.

Declaration
public static UnitType DefaultType { get; set; }
Property Value
UnitType

A UnitType value that defines the default units of measure for a Report.

DotsPerInch

Gets a double value representing the DPI of the current graphics context (the DPI of a device-dependent pixel).

Declaration
public static double DotsPerInch { get; }
Property Value
System.Double

A double value representing the DPI of the current graphics context.

IsEmpty

Specifies whether this Unit structure is uninitialized.

Declaration
public bool IsEmpty { get; }
Property Value
System.Boolean

This property returns true if this unit is uninitialized; otherwise, false.

Type

Gets the type of the Unit.

Declaration
public UnitType Type { get; }
Property Value
UnitType

A UnitType specifying the type of this Unit.

Value

Gets the magnitude of this Unit.

Declaration
public float Value { get; }
Property Value
System.Single

A float value indicating the magnitude of the Unit.

Remarks

This property makes sense only in combination with the Type property.

Methods

Add(Unit)

Adds a unit to this Unit.

Declaration
public Unit Add(Unit unit1)
Parameters
Unit unit1

The Unit to add.

Returns
Unit

The sum of unit1 and this Unit in this Unit's type.

Add(Unit, Unit)

Returns a Unit that is the sum of two units and its unit type matches the first argument type.

Declaration
public static Unit Add(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first Unit.

Unit unit2

The second Unit.

Returns
Unit

The sum of the two units in the unit type of the first argument unit.

Add(Unit, Unit, UnitType)

Returns a Unit that is the sum of two units and is of the specified type.

Declaration
[Obsolete("Use Add(unit1, unit2) and ChangeType(type) instead.")]
public static Unit Add(Unit unit1, Unit unit2, UnitType type)
Parameters
Unit unit1

The first Unit.

Unit unit2

The second Unit.

UnitType type

A UnitType specifying the type of the resultant unit.

Returns
Unit

The sum of the two units.

ChangeType(UnitType)

Returns a unit equal by magnitude to this Unit but with its type changed.

Declaration
public Unit ChangeType(UnitType type)
Parameters
UnitType type

The UnitType to change to.

Returns
Unit

A Unit equal to this Unit, but with type that equals the type parameter.

Cm(Double)

Creates a new Unit of type UnitType.Cm and magnitude equal to value.

Declaration
public static Unit Cm(double value)
Parameters
System.Double value

A double value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Cm(Int32)

Creates a new Unit of type UnitType.Cm and magnitude equal to value.

Declaration
public static Unit Cm(int value)
Parameters
System.Int32 value

An int value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

CompareTo(Object)

Declaration
public int CompareTo(object value)
Parameters
System.Object value

Returns
System.Int32

Implements
System.IComparable.CompareTo(System.Object)

CompareTo(Unit)

Declaration
public int CompareTo(Unit value)
Parameters
Unit value

Returns
System.Int32

Implements
System.IComparable<T>.CompareTo(T)

Divide(Double)

Divides this Unit by a specified value.

Declaration
public Unit Divide(double value)
Parameters
System.Double value

A double value to divide by.

Returns
Unit

The quotient resulting by dividing this Unit by the specified value.

Divide(Unit)

Divides this Unit by another.

Declaration
public float Divide(Unit value)
Parameters
Unit value

A Unit value to divide by.

Returns
System.Single

The quotient resulting by dividing this Unit by the specified Unit.

Equals(Object)

Tests whether obj is a Unit that equals this Unit.

Declaration
public override bool Equals(object obj)
Parameters
System.Object obj

The System.Object to test.

Returns
System.Boolean

This method returns true if obj is a Unit and its magnitude is equal to this Unit's magnitude; otherwise false.

Overrides
System.ValueType.Equals(System.Object)

FromDips(Double, UnitType)

Creates a unit from device-independent pixels in the specified unit type.

Declaration
public static Unit FromDips(double dips, UnitType resultType)
Parameters
System.Double dips

The magnitude of the new Unit in device-independent pixels.

UnitType resultType

The unit type of the newly created Unit

Returns
Unit

Newly created Unit

FromPixels(Double, UnitType)

Creates a unit from device-dependent pixels in the specified unit type.

Declaration
public static Unit FromPixels(double devicePixels, UnitType resultType)
Parameters
System.Double devicePixels

The magnitude of the new Unit in device-dependent pixels.

UnitType resultType

The unit type of the newly created Unit

Returns
Unit

Newly created Unit

GetHashCode()

Returns a hash code for this Unit structure.

Declaration
public override int GetHashCode()
Returns
System.Int32

An integer value that specifies a hash value for this Unit structure.

Overrides
System.ValueType.GetHashCode()

Inch(Double)

Creates a new Unit of type UnitType.Inch and magnitude equal to value.

Declaration
public static Unit Inch(double value)
Parameters
System.Double value

A double value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Inch(Int32)

Creates a new Unit of type UnitType.Inch and magnitude equal to value.

Declaration
public static Unit Inch(int value)
Parameters
System.Int32 value

An int value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Max(Unit, Unit)

Returns the larger of two units.

Declaration
public static Unit Max(Unit val1, Unit val2)
Parameters
Unit val1

The first of two units to compare.

Unit val2

The second of two units to compare.

Returns
Unit

Parameter val1 or val2, whichever is larger.

Min(Unit, Unit)

Returns the smaller of two units.

Declaration
public static Unit Min(Unit val1, Unit val2)
Parameters
Unit val1

The first of two units to compare.

Unit val2

The second of two units to compare.

Returns
Unit

Parameter val1 or val2, whichever is smaller.

Mm(Double)

Creates a new Unit of type UnitType.Mm and magnitude equal to value.

Declaration
public static Unit Mm(double value)
Parameters
System.Double value

A double value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Mm(Int32)

Creates a new Unit of type UnitType.Mm and magnitude equal to value.

Declaration
public static Unit Mm(int value)
Parameters
System.Int32 value

An int value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Multiply(Double)

Multiplies this Unit by a specified value.

Declaration
public Unit Multiply(double value)
Parameters
System.Double value

A double value to multiply by.

Returns
Unit

The product of multiplying this Unit by the specified value.

Parse(String)

Parses a string value to create a new Unit.

Declaration
public static Unit Parse(string value)
Parameters
System.String value

A string value defining the unit.

Returns
Unit

The created Unit.

Remarks

The parameter passed to this Method should be of the form "2px", "3.4in", "4cm", "2mm", "12.5pt", "4pc", etc. For more information on string representations of units see UnitType.

Parse(String, CultureInfo)

Parses a string value to create a new Unit based on the specified culture.

Declaration
public static Unit Parse(string value, CultureInfo culture)
Parameters
System.String value

A string value defining the unit.

System.Globalization.CultureInfo culture

The System.Globalization.CultureInfo object defining the rules for the parsing.

Returns
Unit

The created Unit.

Remarks

The parameter passed to this Method should be of the form "2px", "3.4in", "4cm", "2mm", "12.5pt", "4pc", etc. For more information on string representations of units see UnitType.

Pica(Double)

Creates a new Unit of type UnitType.Pica and magnitude equal to value.

Declaration
public static Unit Pica(double value)
Parameters
System.Double value

A double value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Pica(Int32)

Creates a new Unit of type UnitType.Pica and magnitude equal to value.

Declaration
public static Unit Pica(int value)
Parameters
System.Int32 value

An int value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Pixel(Double)

Creates a new Unit of type UnitType.Pixel and magnitude equal to value in device-independent pixels.

Declaration
public static Unit Pixel(double dips)
Parameters
System.Double dips

A double value specifying the magnitude of the Unit in device-independent pixels (96 DPI pixels or dips).

Returns
Unit

The created Unit.

Pixel(Int32)

Creates a new Unit of type UnitType.Pixel and magnitude equal to value in device-independent pixels.

Declaration
public static Unit Pixel(int dips)
Parameters
System.Int32 dips

An int value specifying the magnitude of the Unit in device-independent pixels (96 DPI pixels or dips).

Returns
Unit

The created Unit.

Point(Double)

Creates a new Unit of type UnitType.Point and magnitude equal to value.

Declaration
public static Unit Point(double value)
Parameters
System.Double value

A double value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Point(Int32)

Creates a new Unit of type UnitType.Point and magnitude equal to value.

Declaration
public static Unit Point(int value)
Parameters
System.Int32 value

An int value specifying the magnitude of the Unit.

Returns
Unit

The created Unit.

Subtract(Unit)

Subtracts a unit from this Unit.

Declaration
public Unit Subtract(Unit unit1)
Parameters
Unit unit1

The Unit to subtract.

Returns
Unit

The difference of this Unit and unit1 in this Unit's type.

Subtract(Unit, Unit)

Returns a Unit that is the difference of two units and is of the specified type.

Declaration
public static Unit Subtract(Unit unit1, Unit unit2)
Parameters
Unit unit1

The Unit to subtract from.

Unit unit2

The Unit to subtract.

Returns
Unit

The difference of the two units in the unit type of the first argument unit.

Subtract(Unit, Unit, UnitType)

Returns a Unit that is the difference of two units and is of the specified type.

Declaration
[Obsolete("Use Telerik.Reporting.Drawing.Subtract(Unit, Unit) and Telerik.Reporting.Drawing.ChangeType(UnitType) instead.")]
public static Unit Subtract(Unit unit1, Unit unit2, UnitType type)
Parameters
Unit unit1

The Unit to subtract from.

Unit unit2

The Unit to subtract.

UnitType type

A UnitType specifying the type of the resultant unit.

Returns
Unit

The difference of the two units in the specified unit type.

ToString()

Returns a human-readable representation of this Unit.

Declaration
public override string ToString()
Returns
System.String

A human-readable representation of this Unit.

Overrides
System.ValueType.ToString()

ToString(CultureInfo)

Returns a human-readable representation of this Unit.

Declaration
public string ToString(CultureInfo culture)
Parameters
System.Globalization.CultureInfo culture

A System.Globalization.CultureInfo specifying the culture to use.

Returns
System.String

A human-readable representation of this Unit.

Operators

Addition(Unit, Unit)

Adds one Unit to another.

Declaration
public static Unit operator +(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first Unit.

Unit unit2

The second Unit.

Returns
Unit

The sum of the two units.

Remarks

If unit1 is empty the method returns unit2. If unit2 is empty the method returns unit1. Otherwise, the method returns the sum of the two units in unit1's type.

Division(Unit, Double)

Divides a Unit by a specified value.

Declaration
public static Unit operator /(Unit unit1, double value)
Parameters
Unit unit1

The Unit to divide.

System.Double value

A double value to divide by.

Returns
Unit

A Unit that is the quotient of unit1 and value.

Division(Unit, Unit)

Divides the first Unit by the second.

Declaration
public static float operator /(Unit unit1, Unit unit2)
Parameters
Unit unit1

A Unit to divide.

Unit unit2

A Unit to divide by.

Returns
System.Single

The quotient resulting by dividing of two Units.

Equality(Unit, Unit)

Compares two units.

Declaration
public static bool operator ==(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first unit to compare.

Unit unit2

The second unit to compare.

Returns
System.Boolean

true if unit1 is equal to unit2; otherwise false.

GreaterThan(Unit, Unit)

Compares two units.

Declaration
public static bool operator>(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first unit to compare.

Unit unit2

The second unit to compare.

Returns
System.Boolean

true if unit1 is greater than unit2; otherwise false.

GreaterThanOrEqual(Unit, Unit)

Compares two units.

Declaration
public static bool operator >=(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first unit to compare.

Unit unit2

The second unit to compare.

Returns
System.Boolean

true if unit1 is greater than or equal to unit2; otherwise false.

Inequality(Unit, Unit)

Compares two units.

Declaration
public static bool operator !=(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first unit to compare.

Unit unit2

The second unit to compare.

Returns
System.Boolean

true if unit1 is not equal to unit2; otherwise false.

LessThan(Unit, Unit)

Compares two units.

Declaration
public static bool operator <(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first unit to compare.

Unit unit2

The second unit to compare.

Returns
System.Boolean

true if unit1 is less than unit2; otherwise false.

LessThanOrEqual(Unit, Unit)

Compares two units.

Declaration
public static bool operator <=(Unit unit1, Unit unit2)
Parameters
Unit unit1

The first unit to compare.

Unit unit2

The second unit to compare.

Returns
System.Boolean

true if unit1 is less than or equal to unit2; otherwise false.

Multiply(Double, Unit)

Multiplies a value by a Unit.

Declaration
public static Unit operator *(double value, Unit unit1)
Parameters
System.Double value

The double value to multiply.

Unit unit1

The Unit to multiply by.

Returns
Unit

A Unit that is the product of value and unit1.

Multiply(Unit, Double)

Multiplies a Unit by a specified value.

Declaration
public static Unit operator *(Unit unit1, double value)
Parameters
Unit unit1

The Unit to multiply.

System.Double value

A double value to multiply by.

Returns
Unit

The product of unit1 and value.

Subtraction(Unit, Unit)

Subtract one Unit from another.

Declaration
public static Unit operator -(Unit unit1, Unit unit2)
Parameters
Unit unit1

The Unit to subtract from.

Unit unit2

The Unit to subtract.

Returns
Unit

The difference of the two units.

Remarks

If unit2 is empty the method returns unit1. Otherwise, the method returns the difference of the two units in unit1's type.

Exceptions
System.ArgumentException

Thrown when unit1 is empty.

UnaryNegation(Unit)

Unary minus. Reverses the sign of Unit

Declaration
public static Unit operator -(Unit unit)
Parameters
Unit unit

The unit to negate.

Returns
Unit

A Unit of the same type as unit but with opposite sign.

Was this article helpful?

Tell us how we can improve this article

Skip
Getting Started
  • Install Now
  • Online Demos
Support Resources
  • Documentation
  • Knowledge Base
  • Videos
  • Reporting Samples Repository
  • Reporting Release History
Community
  • Forums
  • Blogs
  • Reporting Feedback Portal

Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.