133 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			133 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Drawing.Printing;
 | |
| 
 | |
| namespace GoldPrinter
 | |
| {
 | |
| 	public class PrinterMargins : Margins
 | |
| 	{
 | |
| 		private int _width;
 | |
| 
 | |
| 		private int _height;
 | |
| 
 | |
| 		private int _X1;
 | |
| 
 | |
| 		private int _X2;
 | |
| 
 | |
| 		private int _Y1;
 | |
| 
 | |
| 		private int _Y2;
 | |
| 
 | |
| 		public int Width
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				return this._width;
 | |
| 			}
 | |
| 			set
 | |
| 			{
 | |
| 				this._width = value;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		public int Height
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				return this._height;
 | |
| 			}
 | |
| 			set
 | |
| 			{
 | |
| 				this._height = value;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		public int X1
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				return this._X1;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		public int X2
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				return this._X2;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		public int Y1
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				return this._Y1;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		public int Y2
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				return this._Y2;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		public PrinterMargins() : this(1, 1, 1, 1, 0, 0)
 | |
| 		{
 | |
| 		}
 | |
| 
 | |
| 		public PrinterMargins(int left, int right, int top, int bottom, int width, int height) : base(left, right, top, bottom)
 | |
| 		{
 | |
| 			this._width = width;
 | |
| 			this._height = height;
 | |
| 			this.Calculate();
 | |
| 		}
 | |
| 
 | |
| 		public PrinterMargins(PrintDocument printDocument)
 | |
| 		{
 | |
| 			PrinterMargins printerMargins = new PrinterMargins();
 | |
| 			printerMargins = this.GetPrinterMargins(printDocument);
 | |
| 			base.Left = printerMargins.Left;
 | |
| 			base.Right = printerMargins.Right;
 | |
| 			base.Top = printerMargins.Top;
 | |
| 			base.Bottom = printerMargins.Bottom;
 | |
| 			this.Width = printerMargins.Width;
 | |
| 			this.Height = printerMargins.Height;
 | |
| 			this.Calculate();
 | |
| 		}
 | |
| 
 | |
| 		private PrinterMargins GetPrinterMargins(PrintDocument printDocument)
 | |
| 		{
 | |
| 			int left = printDocument.DefaultPageSettings.Margins.Left;
 | |
| 			int right = printDocument.DefaultPageSettings.Margins.Right;
 | |
| 			int top = printDocument.DefaultPageSettings.Margins.Top;
 | |
| 			int bottom = printDocument.DefaultPageSettings.Margins.Bottom;
 | |
| 			int num = printDocument.DefaultPageSettings.PaperSize.Width;
 | |
| 			int num2 = printDocument.DefaultPageSettings.PaperSize.Height;
 | |
| 			if (printDocument.DefaultPageSettings.Landscape)
 | |
| 			{
 | |
| 				this.Swap(ref num, ref num2);
 | |
| 			}
 | |
| 			num = num - left - right;
 | |
| 			num2 = num2 - top - bottom;
 | |
| 			return new PrinterMargins(left, right, top, bottom, num, num2);
 | |
| 		}
 | |
| 
 | |
| 		private void Swap(ref int ValA, ref int ValB)
 | |
| 		{
 | |
| 			int num = ValA;
 | |
| 			ValA = ValB;
 | |
| 			ValB = num;
 | |
| 		}
 | |
| 
 | |
| 		private void Calculate()
 | |
| 		{
 | |
| 			this._X1 = base.Left;
 | |
| 			this._X2 = base.Left + this._width;
 | |
| 			this._Y1 = base.Top;
 | |
| 			this._Y2 = base.Top + this._height;
 | |
| 		}
 | |
| 	}
 | |
| }
 |