/// <summary>
 /// Print: 8 bit pixels greyscaling with variable printer
 /// </summary>
 /// <param name="Ctrl">Control (form or other) that is to be printed</param>
 /// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
 /// <param name="sPrinterName">the name of the printer that has to be used
 /// including its margins</param>
 /// <param name="bPortrait">Printing as portrait (true) or landscape (false)</param>
 public static void Print(Control Ctrl, ColorDepthReduction f8bitPixel,
                          string sPrinterName, bool bPortrait)
 {
     Start(Ctrl, true, null, f8bitPixel,
           sPrinterName, null, bPortrait, null);
     return;
 }
        /// <summary>
        /// Constructor to set all parameters
        /// </summary>
        /// how to use parameters, take a look at description of Start() method
        private FormPrint(Control Ctrl, bool bPrint,
                          //	formatings, convertings
                          ImageFormat fImage, ColorDepthReduction f8bitPixel,
                          //  additional parameters for printing
                          string sPrinterName, Margins aMargins, bool bPortrait,
                          //  additional parameter for saving
                          string sFileName)
        {
            //  call the bitmap in the propriate way
            //		changed 03/22/2007
            //  NET 1.1
            //	=>	GetBitmap in 1.1 Version
            //		calls GetBitmapGdi
            //	NET 2.0
            //	=>	standard version
            //		GetBitmap in 2.0 Version
            //	=>  RichTextBox or WebBrowser
            //		GetBitmapGdi
            ctrl = Ctrl;
                        #if NET_V20
            if (Find_RTF_or_Web(Ctrl))
            {
                bmp = GetBitmapGdi(Ctrl);
            }
            else
            {
                bmp = GetBitmap(Ctrl);
            }
                #elif NET_V11
            bmp = GetBitmap(Ctrl);
                #endif

            //  set all other parameters
            Printing = bPrint;
            //	formatings, convertings
            formatImage     = fImage;
            format8bitPixel = f8bitPixel;
            //  additional parameters for printing
            PrinterName     = sPrinterName;
            PrinterMargins  = aMargins;
            PrinterPortrait = bPortrait;
            //  additional parameter for saving
            SaveFileName = sFileName;
        }
Beispiel #3
0
		/// <summary>
		/// Print: 8 bit pixels as portrait with variable margins
		/// </summary>
		/// <param name="Ctrl">Control (form or other) that is to be printed</param>
		/// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
		/// <param name="aMargins">the page margins that are to be used</param>
		public static void Print(Control Ctrl, ColorDepthReduction f8bitPixel, 
				Margins aMargins) {
			Start(Ctrl, true, null, f8bitPixel, null, aMargins, true, null);
			return;
		}
Beispiel #4
0
		/// <summary>
		/// Print: 8 bit pixels greyscaling as landscape
		/// </summary>
		/// <param name="Ctrl">Control (form or other) that is to be printed</param>
		/// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
		/// <param name="bPortrait">Printing as portrait (true) or landscape (false)</param>
		public static void Print(Control Ctrl, ColorDepthReduction f8bitPixel, 
				bool bPortrait) {
			Start(Ctrl, true, null, f8bitPixel, null, null, bPortrait, null);
			return;
		}
Beispiel #5
0
		/// <summary>
		/// Print: using all possible parameters
		/// </summary>
		/// <param name="Ctrl">Control (form or other) that is to be printed</param>
		/// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
		/// <param name="sPrinterName">the name of the printer that has to be used</param>
		/// <param name="aMargins">the page margins that are to be used</param>
		/// <param name="bPortrait">Printing as portrait (true) or landscape (false)</param>
		public static void Print(Control Ctrl, ColorDepthReduction f8bitPixel, 
				string sPrinterName, Margins aMargins, bool bPortrait) {
			Start(Ctrl, true, null, f8bitPixel, 
		          sPrinterName, aMargins, bPortrait, null);
			return;
		}
Beispiel #6
0
		/// <summary>
		/// Start() combines Print() and Save() to do all of the work
		/// </summary>
		/// <param name="Ctrl">Control (form or other) that is to be printed or saved</param>
		/// <param name="bPrint">Desides whether to print (true) or save (false)</param>
		/// <param name="fImage">System.Drawing.Imaging.ImageFormat by which the bitmap
		/// has to be saved (printing uses png format as standard)</param>
		/// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
		/// <param name="sPrinterName">the name of the printer that is to be used</param>
		/// <param name="aMargins">the page margins that are to be used</param>
		/// <param name="bPortrait">Printing as portrait (true) or landscape (false)</param>
		/// <param name="sFileName">String with the complete filename to which the bitmap
		/// is to be saved (used only if bPrint == true)</param>
		private static void Start(Control Ctrl, bool bPrint,
				//	formatings
				ImageFormat fImage, ColorDepthReduction f8bitPixel, 
				//  additional parameters for printing
				string sPrinterName, Margins aMargins, bool bPortrait,
				//  additional parameter for saving
				string sFileName
			)
		{

			//  add required standard parameters if necessary
			if (fImage == null)
				fImage = ImageFormat.Png;
			if (bPrint) {
				if (sPrinterName == null)
					sPrinterName = "";
				//  orientation and margins are set to the printer standard automatically
			} else {
				#region NET 2.0 a shorter way to check string.IsNullOrEmpty(sFileName)
				//  NET 2.0 - you can use next 'if'-query as follows:
				//      if (String.IsNullOrEmpty(sFileName))
				//      pay attention: String.IsNullOrEmpty() is new in NET 2.0
				//  NET 1.1 - you must use next 'if'-query as follows:
				//      if ((sFileName == null) || (sFileName == ""))
				#endregion
				//  no filename => user's folder, control's name, imageformat as extension
				if ((sFileName == null) || (sFileName == "")) {
					sFileName = System.IO.Path.Combine(
						Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
						Ctrl.Name + "." + fImage.ToString() );
				}
			}

			//  check possible errors, otherwise execute
			if (Ctrl == null) 	//  reserved for further checks
			{
				if (Ctrl == null)
					MessageBox.Show("Control is not defined", "FormPrint.Start");
				else
					MessageBox.Show("Any other error", "FormPrint.Start");
			} else {
				//  create the private formprint class cls
				cls = new FormPrint(Ctrl, bPrint, fImage, f8bitPixel, 
					sPrinterName, aMargins,  bPortrait, sFileName);
				//  execute the required printing resp. saving method
				try {
					if (bPrint) {
						cls.StartPrinting();
					} else {
						cls.StartSaving();
					}
				} finally {
					//  free resources
					cls.bmp.Dispose();
					cls.bmp = null;
					//  in some situations, the next command is useful
					Ctrl.Refresh();
				}
			}
		}
Beispiel #7
0
		/// <summary>
		/// Constructor to set all parameters
		/// </summary>
		/// how to use parameters, take a look at description of Start() method
		private FormPrint(Control Ctrl, bool bPrint,
				//	formatings, convertings
				ImageFormat fImage, ColorDepthReduction f8bitPixel, 
				//  additional parameters for printing
				string sPrinterName, Margins aMargins, bool bPortrait,
				//  additional parameter for saving
				string sFileName)
		{
			//  call the bitmap in the propriate way
			//		changed 03/22/2007
			// 	NET 1.1 
			//	=>	GetBitmap in 1.1 Version 
			//		calls GetBitmapGdi
			//	NET 2.0
			//	=>	standard version
			//		GetBitmap in 2.0 Version 
			//	=>  RichTextBox or WebBrowser
			//		GetBitmapGdi
			ctrl = Ctrl;
			#if NET_V20
			if (Find_RTF_or_Web(Ctrl))
			    bmp = GetBitmapGdi(Ctrl);
			else
				bmp = GetBitmap(Ctrl);
        	#elif NET_V11        
        	bmp = GetBitmap(Ctrl);
        	#endif

			//  set all other parameters
			Printing = bPrint;
			//	formatings, convertings
			formatImage = fImage;
			format8bitPixel = f8bitPixel;
			//  additional parameters for printing
			PrinterName = sPrinterName;
			PrinterMargins = aMargins;
			PrinterPortrait = bPortrait;
			//  additional parameter for saving
			SaveFileName = sFileName;
		}
        /// <summary>
        /// Constructor to set all parameters
        /// </summary>
        /// how to use parameters, take a look at description of Start() method
        private sbFormPrint(Control Ctrl, bool bPrint,
				//	formatting, conversions
				ImageFormat fImage, ColorDepthReduction f8bitPixel, 
				//  additional parameters for printing
				string sPrinterName, Margins aMargins, bool bPortrait,
				//  additional parameter for saving
				string sFileName)
        {
            // Call the bitmap in the appropriate way
            ctrl = Ctrl;
            if (Find_RTF_or_Web(Ctrl))
                bmp = GetBitmapGdi(Ctrl);
            else
                bmp = GetBitmap(Ctrl);

            //  set all other parameters
            Printing = bPrint;
            //	formatting, converting
            formatImage = fImage;
            format8bitPixel = f8bitPixel;
            //  additional parameters for printing
            PrinterName = sPrinterName;
            PrinterMargins = aMargins;
            PrinterPortrait = bPortrait;
            //  additional parameter for saving
            SaveFileName = sFileName;
        }
 /// <summary>
 /// Print: 8 bit pixels as portrait with variable margins
 /// </summary>
 /// <param name="Ctrl">Control (form or other) that is to be printed</param>
 /// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
 /// <param name="aMargins">the page margins that are to be used</param>
 public static void Print(Control Ctrl, ColorDepthReduction f8bitPixel,
                          Margins aMargins)
 {
     Start(Ctrl, true, null, f8bitPixel, null, aMargins, true, null);
     return;
 }
        /// <summary>
        /// Start() combines Print() and Save() to do all of the work
        /// </summary>
        /// <param name="Ctrl">Control (form or other) that is to be printed or saved</param>
        /// <param name="bPrint">Desides whether to print (true) or save (false)</param>
        /// <param name="fImage">System.Drawing.Imaging.ImageFormat by which the bitmap
        /// has to be saved (printing uses png format as standard)</param>
        /// <param name="f8bitPixel">decides how to convert bitmap to 8 bit ColorDepth</param>
        /// <param name="sPrinterName">the name of the printer that is to be used</param>
        /// <param name="aMargins">the page margins that are to be used</param>
        /// <param name="bPortrait">Printing as portrait (true) or landscape (false)</param>
        /// <param name="sFileName">String with the complete filename to which the bitmap
        /// is to be saved (used only if bPrint == true)</param>
        private static void Start(Control Ctrl, bool bPrint,
                                  //	formatings
                                  ImageFormat fImage, ColorDepthReduction f8bitPixel,
                                  //  additional parameters for printing
                                  string sPrinterName, Margins aMargins, bool bPortrait,
                                  //  additional parameter for saving
                                  string sFileName
                                  )
        {
            //  add required standard parameters if necessary
            if (fImage == null)
            {
                fImage = ImageFormat.Png;
            }
            if (bPrint)
            {
                if (sPrinterName == null)
                {
                    sPrinterName = "";
                }
                //  orientation and margins are set to the printer standard automatically
            }
            else
            {
                #region NET 2.0 a shorter way to check string.IsNullOrEmpty(sFileName)
                //  NET 2.0 - you can use next 'if'-query as follows:
                //      if (String.IsNullOrEmpty(sFileName))
                //      pay attention: String.IsNullOrEmpty() is new in NET 2.0
                //  NET 1.1 - you must use next 'if'-query as follows:
                //      if ((sFileName == null) || (sFileName == ""))
                #endregion
                //  no filename => user's folder, control's name, imageformat as extension
                if ((sFileName == null) || (sFileName == ""))
                {
                    sFileName = System.IO.Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
                        Ctrl.Name + "." + fImage.ToString());
                }
            }

            //  check possible errors, otherwise execute
            if (Ctrl == null)                   //  reserved for further checks
            {
                if (Ctrl == null)
                {
                    MessageBox.Show("Control is not defined", "FormPrint.Start");
                }
                else
                {
                    MessageBox.Show("Any other error", "FormPrint.Start");
                }
            }
            else
            {
                //  create the private formprint class cls
                cls = new FormPrint(Ctrl, bPrint, fImage, f8bitPixel,
                                    sPrinterName, aMargins, bPortrait, sFileName);
                //  execute the required printing resp. saving method
                try {
                    if (bPrint)
                    {
                        cls.StartPrinting();
                    }
                    else
                    {
                        cls.StartSaving();
                    }
                } finally {
                    //  free resources
                    cls.bmp.Dispose();
                    cls.bmp = null;
                    //  in some situations, the next command is useful
                    Ctrl.Refresh();
                }
            }
        }