public void SetHdevmode(IntPtr hdevmode)
        {
            // SECREVIEW:
            // PrinterSettings.SetHdevmode demand AllPrintingANDUMC so lets be consistent here.
            IntSecurity.AllPrintingAndUnmanagedCode.Demand();
            if (hdevmode == IntPtr.Zero)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));
            }

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));

            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
            {
                color = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_ORIENTATION) == SafeNativeMethods.DM_ORIENTATION)
            {
                landscape = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            }

            paperSize         = PaperSizeFromMode(mode);
            paperSource       = PaperSourceFromMode(mode);
            printerResolution = PrinterResolutionFromMode(mode);

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copies the relevant information out of the handle and into the PageSettings.
        /// </summary>
        public void SetHdevmode(IntPtr hdevmode)
        {
            if (hdevmode == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Format(SR.InvalidPrinterHandle, hdevmode));
            }

            IntPtr pointer = Interop.Kernel32.GlobalLock(hdevmode);

            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)Marshal.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
            {
                _color = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_ORIENTATION) == SafeNativeMethods.DM_ORIENTATION)
            {
                _landscape = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            }

            _paperSize         = PaperSizeFromMode(mode);
            _paperSource       = PaperSourceFromMode(mode);
            _printerResolution = PrinterResolutionFromMode(mode);

            Interop.Kernel32.GlobalUnlock(hdevmode);
        }
Exemplo n.º 3
0
		// used by PrinterSettings.DefaultPageSettings
		internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
		{
			PrinterSettings = printerSettings;
			this.color = color;
			this.landscape = landscape;
			this.paperSize = paperSize;
			this.paperSource = paperSource;
			this.printerResolution = printerResolution;
		}
Exemplo n.º 4
0
 // used by PrinterSettings.DefaultPageSettings
 internal PageSettings(PrinterSettings printerSettings, bool color, bool landscape, PaperSize paperSize, PaperSource paperSource, PrinterResolution printerResolution)
 {
     PrinterSettings        = printerSettings;
     this.color             = color;
     this.landscape         = landscape;
     this.paperSize         = paperSize;
     this.paperSource       = paperSource;
     this.printerResolution = printerResolution;
 }
Exemplo n.º 5
0
        public PageSettings(PrinterSettings printerSettings)
        {
            PrinterSettings = printerSettings;

            this.color             = printerSettings.DefaultPageSettings.color;
            this.landscape         = printerSettings.DefaultPageSettings.landscape;
            this.paperSize         = printerSettings.DefaultPageSettings.paperSize;
            this.paperSource       = printerSettings.DefaultPageSettings.paperSource;
            this.printerResolution = printerSettings.DefaultPageSettings.printerResolution;
        }
Exemplo n.º 6
0
		public PageSettings(PrinterSettings printerSettings)
		{
			PrinterSettings = printerSettings;
			
			this.color = printerSettings.DefaultPageSettings.color;
			this.landscape = printerSettings.DefaultPageSettings.landscape;
			this.paperSize = printerSettings.DefaultPageSettings.paperSize;
			this.paperSource = printerSettings.DefaultPageSettings.paperSource;
			this.printerResolution = printerSettings.DefaultPageSettings.printerResolution;
		}
Exemplo n.º 7
0
        private void cmdPrintBarcode_Click(object sender, EventArgs e)
        {
            PrintDocument printDoc = new PrintDocument();
            printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
            PrinterSettings prtSettings = new PrinterSettings();
            prtSettings.PrinterName = Global.sDefaultSlipPrinter;

            PrinterResolution x = new PrinterResolution();
            x.Kind = PrinterResolutionKind.Draft;
            prtSettings.DefaultPageSettings.PrinterResolution = x;
            printDoc.PrinterSettings = prtSettings;
            int iBarCodeOnPage = 0;
            bool bPrint = false;
              foreach (DataGridViewRow dgRow in dgPrintBarcodeList.Rows)
              {
               int iBarcodeCount = Convert.ToInt16(dgRow.Cells["clPrintQuantity"].Value.ToString());
               if (iBarcodeCount > 0)
               {
                   int iCount = 0;
                   while (iCount < iBarcodeCount)
                   {
                       bPrint = true;
                       aBarcodes.Add(dgRow.Cells["clRawItemBarcode"].Value.ToString());
                       aBarcodeNames.Add(dgRow.Cells["clItemCode"].Value.ToString());

                       iCount++;
                       iBarCodeOnPage++;
                       if (iBarCodeOnPage == 4)
                       {
                           printDoc.Print();
                           bPrint = false;
                           aBarcodeNames = new ArrayList();

                           aBarcodes = new ArrayList();
                           iBarCodeOnPage = 0;

                       }

                   }

               }
              }

              if (bPrint)
              {
              printDoc.Print();

              }
              this.Close();

              frmStoreManagementScanning.Enabled = true;
              frmStoreManagementScanning.cmdSubmit.Enabled = true;
              //this.ActiveControl = frmStoreManagementScanning.txtScan;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Provides some interesting information about the PageSettings in String form.
 /// </summary>
 public override string ToString()
 {
     return("[PageSettings:"
            + " Color=" + Color.ToString()
            + ", Landscape=" + Landscape.ToString()
            + ", Margins=" + Margins.ToString()
            + ", PaperSize=" + PaperSize.ToString()
            + ", PaperSource=" + PaperSource.ToString()
            + ", PrinterResolution=" + PrinterResolution.ToString()
            + "]");
 }
        private void cmdPrintAll_Click(object sender, EventArgs e)
        {
            PrintDocument printDoc = new PrintDocument();
            printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage1);
            PrinterSettings prtSettings = new PrinterSettings();

            prtSettings.PrinterName = Global.sDefaultDocPrinter;

            PrinterResolution x = new PrinterResolution();
            x.Kind = PrinterResolutionKind.Draft;
            prtSettings.DefaultPageSettings.PrinterResolution = x;
            printDoc.PrinterSettings = prtSettings;
            printDoc.Print();
        }
Exemplo n.º 10
0
        public object Clone()
        {
            // We do a deep copy
            PrinterResolution pres    = new PrinterResolution(this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
            PaperSource       psource = new PaperSource(this.paperSource.SourceName, this.paperSource.Kind);
            PaperSize         psize   = new PaperSize(this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);

            psize.SetKind(this.paperSize.Kind);

            PageSettings ps = new PageSettings(this.printerSettings, this.color, this.landscape,
                                               psize, psource, pres);

            ps.Margins = (Margins)this.margins.Clone();
            return(ps);
        }
Exemplo n.º 11
0
        // Convert this object into a string.
        public override String ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("[PageSettings: Color=");
            builder.Append(Color.ToString());
            builder.Append(", Landscape=");
            builder.Append(Landscape.ToString());
            builder.Append(", Margins=");
            builder.Append(Margins.ToString());
            builder.Append(", PaperSize=");
            builder.Append(PaperSize.ToString());
            builder.Append(", PaperSource=");
            builder.Append(PaperSource.ToString());
            builder.Append(", PrinterResolution=");
            builder.Append(PrinterResolution.ToString());
            builder.Append(']');
            return(builder.ToString());
        }
Exemplo n.º 12
0
        /// <include file='doc\PageSettings.uex' path='docs/doc[@for="PageSettings.SetHdevmode"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Copies the relevant information out of the handle and into the PageSettings.
        ///    </para>
        /// </devdoc>
        public void SetHdevmode(IntPtr hdevmode)
        {
            IntSecurity.AllPrinting.Demand();

            if (hdevmode == IntPtr.Zero)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));
            }

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));

            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE)UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            color             = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            landscape         = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            paperSize         = PaperSizeFromMode(mode);
            paperSource       = PaperSourceFromMode(mode);
            printerResolution = PrinterResolutionFromMode(mode);

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
Exemplo n.º 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the default page settings from the default printer on the macine. If no printer
		/// is installed, set them to null.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private static void TryCreateDefaultPageSettings()
		{
			if (!s_fTriedToGetDefautSettings)
			{
				try
				{
					PrinterSettings defaultPrintSettings = new PrinterSettings();
					Debug.Assert(defaultPrintSettings.IsDefaultPrinter);
					// ENHANCE (TE-5917): Detect when the default printer changes and update
					// accordinly.
					PageSettings pageSettings = defaultPrintSettings.DefaultPageSettings;
					s_defaultpaperSize = pageSettings.PaperSize;
					s_defaultPrinterResolution = pageSettings.PrinterResolution;
				}
				catch
				{
					// Printer is not installed or maybe there is a problem with the driver.
					s_defaultpaperSize = null;
					s_defaultPrinterResolution = null;
				}
				s_fTriedToGetDefautSettings = true;
			}
		}
 public void CopyTo(PrinterResolution[] printerResolutions, int index)
 {
     Array.Copy(this.array, index, printerResolutions, 0, this.array.Length);
 }
 public int Add(PrinterResolution printerResolution)
 {
     PrinterResolution[] array = new PrinterResolution[this.Count + 1];
     ((ICollection) this).CopyTo(array, 0);
     array[this.Count] = printerResolution;
     this.array = array;
     return this.Count;
 }
 public PrinterResolutionCollection(PrinterResolution[] array)
 {
     this.array = array;
 }
Exemplo n.º 17
0
			internal int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
Exemplo n.º 18
0
			public void CopyTo (PrinterResolution[] printerResolutions, int index) {throw new NotImplementedException (); }
Exemplo n.º 19
0
 public Int32 Add(PrinterResolution printerResolution)
 {
     PrinterResolution[] newArray = new PrinterResolution[this.Count + 1];
     ((ICollection) this).CopyTo(newArray, 0);
     newArray[this.Count] = printerResolution;
     this.array = newArray;
     return this.Count;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Helper method that creates string representation of the PrinterResolution
 /// </summary>
 /// <param name="res">PrinterResolution object to create string representation of</param>
 /// <returns>String containing resolution</returns>
 private string ResolutionString(PrinterResolution res)
 {
     string resolution = res.Kind.ToString();
     if (resolution.Equals("Custom"))
     {
         resolution = string.Format("{0} ({1} x {2})", res.Kind, res.X, res.Y);
     }
     return resolution;
 }
Exemplo n.º 21
0
 public int Add(PrinterResolution printerResolution)
 {
     throw null;
 }
Exemplo n.º 22
0
        public void SetHdevmode(IntPtr hdevmode) {
            // SECREVIEW: 
            // PrinterSettings.SetHdevmode demand AllPrintingANDUMC so lets be consistent here.
            IntSecurity.AllPrintingAndUnmanagedCode.Demand();
            if (hdevmode == IntPtr.Zero)
                throw new ArgumentException(SR.GetString(SR.InvalidPrinterHandle, hdevmode));

            IntPtr pointer = SafeNativeMethods.GlobalLock(new HandleRef(null, hdevmode));
            SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(pointer, typeof(SafeNativeMethods.DEVMODE));

            if ((mode.dmFields & SafeNativeMethods.DM_COLOR) == SafeNativeMethods.DM_COLOR)
            {
                color = (mode.dmColor == SafeNativeMethods.DMCOLOR_COLOR);
            }

            if ((mode.dmFields & SafeNativeMethods.DM_ORIENTATION) == SafeNativeMethods.DM_ORIENTATION)
            {
                landscape = (mode.dmOrientation == SafeNativeMethods.DMORIENT_LANDSCAPE);
            }
            
            paperSize = PaperSizeFromMode(mode);
            paperSource = PaperSourceFromMode(mode);
            printerResolution = PrinterResolutionFromMode(mode);

            SafeNativeMethods.GlobalUnlock(new HandleRef(null, hdevmode));
        }
 public int Add(PrinterResolution printerResolution)
 {
     return(_PrinterResolutions.Add(printerResolution));
 }
Exemplo n.º 24
0
        internal PrinterResolution[] Get_PrinterResolutions() {
            IntSecurity.AllPrintingAndUnmanagedCode.Assert();

            string printerName = PrinterName; //  this is quite expensive if PrinterName is left default
            PrinterResolution[] result;

            int count = FastDeviceCapabilities(SafeNativeMethods.DC_ENUMRESOLUTIONS, IntPtr.Zero, -1, printerName);
            if (count == -1) {
                //Just return the standrard values if custom resolutions absemt ....
                result = new PrinterResolution[4];
                result[0] = new PrinterResolution(PrinterResolutionKind.High, -4, -1);
                result[1] = new PrinterResolution(PrinterResolutionKind.Medium, -3, -1);
                result[2] = new PrinterResolution(PrinterResolutionKind.Low, -2, -1);
                result[3] = new PrinterResolution(PrinterResolutionKind.Draft, -1, -1);
                
                return result;
            }
            
            result = new PrinterResolution[count + 4];
            result[0] = new PrinterResolution(PrinterResolutionKind.High, -4, -1);
            result[1] = new PrinterResolution(PrinterResolutionKind.Medium, -3, -1);
            result[2] = new PrinterResolution(PrinterResolutionKind.Low, -2, -1);
            result[3] = new PrinterResolution(PrinterResolutionKind.Draft, -1, -1);

            IntPtr buffer = Marshal.AllocCoTaskMem(checked(8 * count));
            FastDeviceCapabilities(SafeNativeMethods.DC_ENUMRESOLUTIONS, buffer, -1, printerName);
            
            for (int i = 0; i < count; i++) {
                int x = Marshal.ReadInt32((IntPtr)(checked((long)buffer + i*8)));
                int y = Marshal.ReadInt32((IntPtr)(checked((long)buffer + i*8 + 4)));
                result[i + 4] = new PrinterResolution(PrinterResolutionKind.Custom, x, y);
            }

            Marshal.FreeCoTaskMem(buffer);
            return result;
        }
 internal PrinterResolution[] Get_PrinterResolutions()
 {
     System.Drawing.IntSecurity.AllPrintingAndUnmanagedCode.Assert();
     string printerName = this.PrinterName;
     int num = FastDeviceCapabilities(13, IntPtr.Zero, -1, printerName);
     if (num == -1)
     {
         return new PrinterResolution[] { new PrinterResolution(PrinterResolutionKind.High, -4, -1), new PrinterResolution(PrinterResolutionKind.Medium, -3, -1), new PrinterResolution(PrinterResolutionKind.Low, -2, -1), new PrinterResolution(PrinterResolutionKind.Draft, -1, -1) };
     }
     PrinterResolution[] resolutionArray = new PrinterResolution[num + 4];
     resolutionArray[0] = new PrinterResolution(PrinterResolutionKind.High, -4, -1);
     resolutionArray[1] = new PrinterResolution(PrinterResolutionKind.Medium, -3, -1);
     resolutionArray[2] = new PrinterResolution(PrinterResolutionKind.Low, -2, -1);
     resolutionArray[3] = new PrinterResolution(PrinterResolutionKind.Draft, -1, -1);
     IntPtr pointerToBuffer = Marshal.AllocCoTaskMem(8 * num);
     FastDeviceCapabilities(13, pointerToBuffer, -1, printerName);
     for (int i = 0; i < num; i++)
     {
         int x = Marshal.ReadInt32((IntPtr) (((long) pointerToBuffer) + (i * 8)));
         int y = Marshal.ReadInt32((IntPtr) ((((long) pointerToBuffer) + (i * 8)) + 4L));
         resolutionArray[i + 4] = new PrinterResolution(PrinterResolutionKind.Custom, x, y);
     }
     Marshal.FreeCoTaskMem(pointerToBuffer);
     return resolutionArray;
 }
Exemplo n.º 26
0
			public PrinterResolutionCollection(PrinterResolution[] array) {
				foreach (PrinterResolution pr in array)
					_PrinterResolutions.Add(pr);
			}
Exemplo n.º 27
0
 private void PrintImage(Image iPic)
 {
     // общие настройки
     printDocument1.DefaultPageSettings.Landscape = false;
     PrinterResolution pkResolution = new PrinterResolution();
     pkResolution.X = 204;
     pkResolution.Y = 200;
     printDocument1.DefaultPageSettings.PrinterResolution = pkResolution;
     printDocument1.DefaultPageSettings.Margins.Bottom = 8;
     printDocument1.DefaultPageSettings.Margins.Left = 0;
     printDocument1.DefaultPageSettings.Margins.Right = 8;
     printDocument1.DefaultPageSettings.Margins.Top = 0;
     // форматируем
     if (iPic.Width > iPic.Height) iPic.RotateFlip(RotateFlipType.Rotate90FlipNone);
     // задаем размер страницы
     printDocument1.DefaultPageSettings.PaperSize = getPaperSize(iPic);
     printPreviewDialog1.Document = printDocument1;
     printDocument1.Print();
       /*  // выбрасываем распечатку, это круто
     printDocument1.DefaultPageSettings.PaperSize.Height = 0;
     printDocument1.DefaultPageSettings.PaperSize.Width = 0;
     printPreviewDialog1.Document = printDocument1;
     printDocument1.Print();*/
 }
Exemplo n.º 28
0
			public int Add (PrinterResolution printerResolution) { return _PrinterResolutions.Add (printerResolution); }
Exemplo n.º 29
0
 /// <summary>
 /// Constructor
 /// </summary>
 public PrintProperties()
 {
     UserPreferences prefs = ((App)Application.Current).UserPreferences;
     PrinterName = prefs.DefaultPrinterName;
     PrinterPaperSize = new PaperSize(prefs.DefaultPaperSize.PaperName,
                                      prefs.DefaultPaperSize.Width,
                                      prefs.DefaultPaperSize.Height);
     Resolution = new PrinterResolution();
     Resolution.Kind = prefs.DefaultPrinterResolution.Kind;
     Resolution.X = prefs.DefaultPrinterResolution.X;
     Resolution.Y = prefs.DefaultPrinterResolution.Y;
     Source = prefs.DefaultPaperSource;
     InsideMargins = prefs.InsideMargins;
     PrintCardOutlines = prefs.PrintCardOutlines;
     FillLastPage = prefs.FillLastPage;
     SetCardMargins = prefs.SetCardMargins;
     Layout = PrintProperties.CardLayouts.PortraitTopLeft;
     if(App.Logger.DebugPrinting)
     {
         string debugMsg = "In PrintProperties constructor:" +
             Environment.NewLine + this.ToString();
         App.Logger.Log(debugMsg);
     }
 }
Exemplo n.º 30
0
		public object Clone ()
		{
			// We do a deep copy
			PrinterResolution pres = new PrinterResolution (this.printerResolution.X, this.printerResolution.Y, this.printerResolution.Kind);
			PaperSource psource = new PaperSource (this.paperSource.SourceName, this.paperSource.Kind);
			PaperSize psize = new PaperSize (this.paperSize.PaperName, this.paperSize.Width, this.paperSize.Height);
			psize.SetKind (this.paperSize.Kind);

			PageSettings ps = new PageSettings (this.printerSettings, this.color, this.landscape,
					psize, psource, pres);
			ps.Margins = (Margins) this.margins.Clone ();
			return ps;
		}