Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CommonUI / System / Drawing / Printing / PrinterUnitConvert.cs / 1 / PrinterUnitConvert.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing.Printing { using System.Runtime.InteropServices; using System.Diagnostics; using System; using System.Drawing; using System.ComponentModel; using Microsoft.Win32; ////// /// public sealed class PrinterUnitConvert { private PrinterUnitConvert() { } ////// Specifies a series of conversion methods that are /// useful when interoperating with the raw Win32 printing API. /// This class cannot be inherited. /// ////// /// public static double Convert(double value, PrinterUnit fromUnit, PrinterUnit toUnit) { double fromUnitsPerDisplay = UnitsPerDisplay(fromUnit); double toUnitsPerDisplay = UnitsPerDisplay(toUnit); return value * toUnitsPerDisplay / fromUnitsPerDisplay; } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static int Convert(int value, PrinterUnit fromUnit, PrinterUnit toUnit) { return(int) Math.Round(Convert((double)value, fromUnit, toUnit)); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Point Convert(Point value, PrinterUnit fromUnit, PrinterUnit toUnit) { return new Point( Convert(value.X, fromUnit, toUnit), Convert(value.Y, fromUnit, toUnit) ); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Size Convert(Size value, PrinterUnit fromUnit, PrinterUnit toUnit) { return new Size( Convert(value.Width, fromUnit, toUnit), Convert(value.Height, fromUnit, toUnit) ); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Rectangle Convert(Rectangle value, PrinterUnit fromUnit, PrinterUnit toUnit) { return new Rectangle( Convert(value.X, fromUnit, toUnit), Convert(value.Y, fromUnit, toUnit), Convert(value.Width, fromUnit, toUnit), Convert(value.Height, fromUnit, toUnit) ); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Margins Convert(Margins value, PrinterUnit fromUnit, PrinterUnit toUnit) { Margins result = new Margins(); result.Left = Convert(value.Left, fromUnit, toUnit); result.Right = Convert(value.Right, fromUnit, toUnit); result.Top = Convert(value.Top, fromUnit, toUnit); result.Bottom = Convert(value.Bottom, fromUnit, toUnit); return result; } private static double UnitsPerDisplay(PrinterUnit unit) { double result; switch (unit) { case PrinterUnit.Display: result = 1.0; break; case PrinterUnit.ThousandthsOfAnInch: result = 10.0; break; case PrinterUnit.HundredthsOfAMillimeter: result = 25.4; break; case PrinterUnit.TenthsOfAMillimeter: result = 2.54; break; default: Debug.Fail("Unknown PrinterUnit " + unit); result = 1.0; break; } return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ ///// Converts the value, in fromUnit units, to toUnit units. /// ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing.Printing { using System.Runtime.InteropServices; using System.Diagnostics; using System; using System.Drawing; using System.ComponentModel; using Microsoft.Win32; ////// /// public sealed class PrinterUnitConvert { private PrinterUnitConvert() { } ////// Specifies a series of conversion methods that are /// useful when interoperating with the raw Win32 printing API. /// This class cannot be inherited. /// ////// /// public static double Convert(double value, PrinterUnit fromUnit, PrinterUnit toUnit) { double fromUnitsPerDisplay = UnitsPerDisplay(fromUnit); double toUnitsPerDisplay = UnitsPerDisplay(toUnit); return value * toUnitsPerDisplay / fromUnitsPerDisplay; } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static int Convert(int value, PrinterUnit fromUnit, PrinterUnit toUnit) { return(int) Math.Round(Convert((double)value, fromUnit, toUnit)); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Point Convert(Point value, PrinterUnit fromUnit, PrinterUnit toUnit) { return new Point( Convert(value.X, fromUnit, toUnit), Convert(value.Y, fromUnit, toUnit) ); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Size Convert(Size value, PrinterUnit fromUnit, PrinterUnit toUnit) { return new Size( Convert(value.Width, fromUnit, toUnit), Convert(value.Height, fromUnit, toUnit) ); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Rectangle Convert(Rectangle value, PrinterUnit fromUnit, PrinterUnit toUnit) { return new Rectangle( Convert(value.X, fromUnit, toUnit), Convert(value.Y, fromUnit, toUnit), Convert(value.Width, fromUnit, toUnit), Convert(value.Height, fromUnit, toUnit) ); } ////// Converts the value, in fromUnit units, to toUnit units. /// ////// /// public static Margins Convert(Margins value, PrinterUnit fromUnit, PrinterUnit toUnit) { Margins result = new Margins(); result.Left = Convert(value.Left, fromUnit, toUnit); result.Right = Convert(value.Right, fromUnit, toUnit); result.Top = Convert(value.Top, fromUnit, toUnit); result.Bottom = Convert(value.Bottom, fromUnit, toUnit); return result; } private static double UnitsPerDisplay(PrinterUnit unit) { double result; switch (unit) { case PrinterUnit.Display: result = 1.0; break; case PrinterUnit.ThousandthsOfAnInch: result = 10.0; break; case PrinterUnit.HundredthsOfAMillimeter: result = 25.4; break; case PrinterUnit.TenthsOfAMillimeter: result = 2.54; break; default: Debug.Fail("Unknown PrinterUnit " + unit); result = 1.0; break; } return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007./// Converts the value, in fromUnit units, to toUnit units. /// ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GeneralTransform3DTo2DTo3D.cs
- ViewBox.cs
- TickBar.cs
- TextureBrush.cs
- IsolatedStorageException.cs
- FontDriver.cs
- PageTheme.cs
- ItemMap.cs
- CannotUnloadAppDomainException.cs
- XmlQueryType.cs
- HtmlPhoneCallAdapter.cs
- GC.cs
- CollectionView.cs
- SettingsAttributes.cs
- MetadataPropertyvalue.cs
- URL.cs
- HybridDictionary.cs
- exports.cs
- PropertyItemInternal.cs
- PackagePartCollection.cs
- MaskedTextBoxDesignerActionList.cs
- CustomValidator.cs
- CompoundFileReference.cs
- DataStreamFromComStream.cs
- Vertex.cs
- UnsafeNativeMethods.cs
- RemotingServices.cs
- AccessDataSource.cs
- ThreadStartException.cs
- FontStyleConverter.cs
- FamilyCollection.cs
- PasswordPropertyTextAttribute.cs
- SystemFonts.cs
- BufferBuilder.cs
- DocumentGridPage.cs
- XmlNodeReader.cs
- ProfileService.cs
- OracleDataAdapter.cs
- MdiWindowListStrip.cs
- PageAsyncTaskManager.cs
- SafeSystemMetrics.cs
- StylusDevice.cs
- SwitchAttribute.cs
- DataControlFieldCollection.cs
- FileUpload.cs
- TraceLog.cs
- OracleConnectionString.cs
- HttpModule.cs
- StubHelpers.cs
- AppDomainFactory.cs
- FrameSecurityDescriptor.cs
- HitTestParameters.cs
- FillRuleValidation.cs
- EdmItemCollection.OcAssemblyCache.cs
- SoapIncludeAttribute.cs
- Vector3DAnimation.cs
- CmsInterop.cs
- AspCompat.cs
- XmlNamespaceDeclarationsAttribute.cs
- PropertyInformationCollection.cs
- SqlRowUpdatingEvent.cs
- DoubleLink.cs
- XmlTextReader.cs
- MatrixTransform.cs
- RepeaterItem.cs
- OleDbWrapper.cs
- MultipleViewPattern.cs
- UnionExpr.cs
- BlurEffect.cs
- RouteParametersHelper.cs
- ObjectConverter.cs
- StoreAnnotationsMap.cs
- ThicknessAnimation.cs
- CreateInstanceBinder.cs
- AppSettingsExpressionEditor.cs
- SqlDataSourceCache.cs
- SecurityUniqueId.cs
- ShaperBuffers.cs
- DiffuseMaterial.cs
- OrderPreservingSpoolingTask.cs
- FileDialog.cs
- SafeRightsManagementHandle.cs
- ComponentEvent.cs
- DefaultHttpHandler.cs
- HasRunnableWorkflowEvent.cs
- EventProviderClassic.cs
- ReceiveContextCollection.cs
- MenuEventArgs.cs
- CopyOnWriteList.cs
- NetPipeSection.cs
- MouseButtonEventArgs.cs
- PostBackTrigger.cs
- CompiledQueryCacheEntry.cs
- RayMeshGeometry3DHitTestResult.cs
- GlobalAclOperationRequirement.cs
- SafeHandles.cs
- DescendantBaseQuery.cs
- _SslState.cs
- MailMessageEventArgs.cs
- ValidationErrorInfo.cs