Advertisement
GlobalAccessSoftware

MyPrintClass.cs

Apr 26th, 2019
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.10 KB | None | 0 0
  1.  
  2.  
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // MyCustomPrintLibrary.MyPrintClass.cs
  5. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  6. // Global  Access  Software  InTernational
  7. // Copyrighted (c) 2019 by John P. Edwards
  8. // First Created December 02, 2014 2:53 AM
  9. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  10. // Split this section out to simplify PMP
  11. // v2.5.0.61 Nov 05 2016 05:52 AM
  12. // v2.5.0.79 Nov 12 2016 05:52 AM
  13. // Custom Brush below fixes that!
  14. // v3.6.4.81 Jan 02 2017 Final:
  15. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  16. // Brought this one in from MyLilBlackBook:
  17. // v4.9.5.95 20-Dec-2018 PB.MyPrintEvent1
  18. // v4.9.5.96 31-Dec Revision simplifies.
  19. // v4.9.5.98 12-Jan-2019 Moved to Project.
  20. // v5.0.5.98 12-Jan-2019 Integrate to Beta.
  21. // v5.0.5.99 15-Jan-2019 MCPL Design change.
  22. // v5.0.6.01 22-Feb-2019 Dialing it all in Now!
  23. // v5.0.6.01 02-Mar-2019 Fixedwell w/MPP Menu
  24. // items calling back across, etc.
  25. // v5.0.6.01 06-Mar-2019
  26. // v5.0.6.02 08-Mar-2019 Batch Stuff & Debug
  27. // v5.0.6.03 14-Mar-2019 ReSetPages Call.
  28. // v5.1.7.09 24-Apr-2019 Debugged & Tested.
  29. // v5.1.7.10 25-Apr Instance-N Font stuff.
  30. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  31.  
  32. // Standard Libraries
  33. using System.Drawing.Printing;
  34. using System.IO;
  35. using System.Threading;
  36. using System.Windows.Forms;
  37.  
  38. // Custom Class Aliases
  39. using MCC = MyCustomControls.CustomControl;
  40. using MPE = MyCustomPrintLibrary.MyPrintEvent;
  41.  
  42. // Custom Property Aliases
  43. using MPR = MyCustomPrintLibrary
  44.   .Properties.Resources;
  45. using MPS = MyCustomPrintLibrary
  46.   .Properties.Settings;
  47.  
  48.  
  49. namespace MyCustomPrintLibrary
  50. {
  51.   public static class MyPrintClass // MPC
  52.   {
  53.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  54.  
  55.     public static string Open
  56.     { get { using (LockOut)
  57.       { return Open1; } } }
  58.  
  59.     // bug Not really, just follow the
  60.     // model above for the rest of these.
  61.     k
  62.     private static string Open1
  63.     { get { return MPR.Open; } }
  64.  
  65.     public static string PreviewFile
  66.     { get { return Preview; } }
  67.  
  68.     private static string Preview
  69.     { get { return MPR.Preview; } }
  70.  
  71.     public static string PrintFile
  72.     { get { return Print; } }
  73.  
  74.     private static string Print
  75.     { get { return MPR.Print; } }
  76.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  77.  
  78.     public static bool ShowPaper
  79.     {
  80.       get { return Paper; }
  81.       set { Paper = value;}
  82.     }
  83.  
  84.     private static bool Paper
  85.     {
  86.       get
  87.       {
  88.         return MPS.Default.ShowBg;
  89.       }
  90.       set
  91.       {
  92.         MPS.Default.ShowBg = value;
  93.         MPS.Default.Save();
  94.       }
  95.     }
  96.  
  97.     public static byte QuitCode
  98.     {
  99.       get { return Code; }
  100.       set { Code = value;}
  101.     }
  102.  
  103.     private static byte Code
  104.     {
  105.       get
  106.       {
  107.         using (Mutex1)
  108.         {
  109.           return MPS.Default.MppExit;
  110.         }
  111.       }
  112.       set
  113.       {
  114.         using (Mutex1)
  115.         {
  116.           MPS.Default.MppExit = value;
  117.           MPS.Default.Save();
  118.         }
  119.       }
  120.     }
  121.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  122.  
  123.     internal static readonly
  124.       Mutex LockOut = new Mutex(false,
  125.         "LocalSettingsLockoutMutex");
  126.  
  127.     private static readonly Mutex  Mutex1 =
  128.       new Mutex(false,"MyPrintClassMutex1");
  129.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  130.  
  131.     internal static PageSettings PageSet
  132.     { set { PageS = value; } }
  133.  
  134.     private static PageSettings PageS
  135.     {
  136.       set
  137.       {
  138.         using (Mutex1)
  139.         {
  140.           MPS.Default.PageSet = value;
  141.           MPS.Default.Save();
  142.         }
  143.       }
  144.     }
  145.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  146.  
  147.     internal static PrinterSettings PrintSet
  148.     { set { Set1 = value; } }
  149.  
  150.     private static PrinterSettings Set1
  151.     {
  152.       set
  153.       {
  154.         using (Mutex1)
  155.         {
  156.           //Mutex1.WaitOne();
  157.           MPS.Default.PrintSet =
  158.             MPS.Default.PageSet
  159.               .PrinterSettings = value;
  160.         }
  161.         // also ^ sets
  162.         // pagesettings.printersettings.
  163.         // which calls MPS.Default.Save();
  164.         //Mutex1.ReleaseMutex();
  165.       }
  166.     }
  167.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  168.    
  169.     internal static PrintDocument MyPrintDoc
  170.     { get { return PrintDoc; } }
  171.  
  172.     private static PrintDocument PrintDoc
  173.     { get { return GetPrintDoc(); } }
  174.  
  175.     /* MyCustomControls Dox
  176.      ****************************
  177.      * O1 = MyOpenDialog;
  178.      * R1 = MyRichTextBox;
  179.      * P1 = MyPrintDialog;
  180.      * P2 = MyPreviewControl;
  181.      * P3 = MyPreviewDialog;
  182.      * D1 = MyPrintDoc;
  183.      * P4 = MyPageSetup;
  184.      * M1 = MyPreviewMenuStrip;
  185.      * M2 = MyColorDialog;
  186.      * F0 = MyFontDialog;
  187.      * S1 = MySaveDialog;
  188.      ****************************
  189.     */
  190.  
  191.     // CheckSettings, get defaults
  192.     // if nothing else is saved yet.
  193.     private static
  194.       PrintDocument GetPrintDoc()
  195.     {
  196.       //Mutex1.WaitOne();
  197.       using (Mutex1)
  198.       {
  199.         PrintDocument doc;
  200.         using (var mcc = new MCC())
  201.         {
  202.           doc = mcc.D1;
  203.           if (MPS.Default.PageSet  != null)
  204.             doc.DefaultPageSettings =
  205.               MPS.Default.PageSet;
  206.           else MPS.Default.PageSet  =
  207.             mcc.P4.PageSettings;
  208.           if (MPS.Default.PrintSet != null)
  209.             doc.PrinterSettings     =
  210.               MPS.Default.PrintSet;
  211.           else MPS.Default.PrintSet =
  212.             mcc.P1.PrinterSettings;
  213.           doc.PrintController = mcc.P1
  214.             .Document.PrintController;
  215.         }
  216.         doc.DefaultPageSettings
  217.           .PrinterSettings.PrintFileName =
  218.           doc.DocumentName =
  219.           doc.PrinterSettings
  220.             .PrintFileName = MPR.Randy;
  221.         // Set EventHandlers
  222.         doc.PrintPage  +=
  223.           MPE.PrintPageEventHandler;
  224.         #region Optional Events Begin/End
  225.         //doc.BeginPrint +=
  226.         //  MPE.MyBeginPrintEventHandler;
  227.         //// develop as needed.
  228.         //doc.EndPrint   +=
  229.         //  MPE.MyEndPrintEventHandler;
  230.         #endregion
  231.         //Mutex1.ReleaseMutex();
  232.         return doc;
  233.       }
  234.     }
  235.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  236.  
  237.  
  238.     internal static void ReSetPages()
  239.     {
  240.       var temp = MyPrintDoc;
  241.       temp.PrinterSettings.FromPage =
  242.         temp.PrinterSettings.ToPage = 0;
  243.       temp.PrinterSettings.PrintRange =
  244.         PrintRange.AllPages;
  245.       PrintSet = temp.PrinterSettings;
  246.       // develop Any other "tween PrintJobs"
  247.     }
  248.  
  249.     internal static bool IsFile(string f)
  250.     {
  251.       return f.Contains("\\")
  252.         && f.Contains(":")
  253.         && File.Exists(f);
  254.     }
  255.  
  256.     internal static void
  257.       GetContent(string file)
  258.     {
  259.       using (var c = new MCC())
  260.       {
  261.         var rtb = c.R1;
  262.         var ext = Path.GetExtension(file);
  263.         if(string.IsNullOrEmpty(ext))return;
  264.         if (!ext.Equals(".rtf"))
  265.         { rtb.LoadFile(file,
  266.             RichTextBoxStreamType.PlainText);
  267.           MPE.DocContents = rtb.Text; }
  268.         else {// design hack GetContent4(RTFs)
  269.           rtb.LoadFile(file,
  270.             RichTextBoxStreamType.RichText);
  271.           MPE.DocContents = rtb.Rtf; }
  272.       }
  273.     }
  274.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  275.  
  276.  
  277.   }
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement