Convert value of NLength to different measurement unit


Author
Message
Kevin Harrison 1
Kevin Harrison 1
Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)
Group: Forum Members
Posts: 176, Visits: 1.9K

Is it possible to easily an NLength in one measurement unit into a different measurement unit?

e.g. I have a length in NGraphicsUnit.Pixel which I want to convert to NRelativeUnit.ParentPercentage

Thanks

Kevin


Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
Hi Kevin,

Yes there is an easy way to convert values from one measurement unit to another. The following code shows how to create and initialize a measurement unit converter class that can be used to perform this conversion:

NMeasurementUnitConverter converter = new NMeasurementUnitConverter(NResolution.ScreenResolution);

NSizeF rootSize = new NSizeF(200, 200);
NSizeF parentSize = new NSizeF(100, 100);
converter.InitializeRelativeMembers(rootSize, parentSize);

float parentPercentage = converter.ConvertX(NGraphicsUnit.Pixel, NRelativeUnit.ParentPercentage, 10);

Note that in general the conversion is defined when you specify x/y resolution, x/y parent size (used by the ParentPercentage unit) and x/y root size (used by the RootPercentageUnit). Hope this helps - let us know if you have any questions...

Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search