Advertisement
GlobalAccessSoftware

MyPrintEvent1.cs

Apr 26th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.79 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.02 08-Mar-2019 Batch Stuff & Debug
  26. // v5.0.6.03 14-Mar-2019 ReSetPages Call.
  27. // v5.0.6.03 16-Mar-2019 Split to simplify.
  28. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  29.  
  30. using System.Drawing.Printing;
  31. using System.Threading;
  32.  
  33. using MCC = MyCustomControls.CustomControl;
  34. using MPC = MyCustomPrintLibrary.MyPrintClass;
  35. using MFC = MyCustomPrintLibrary.MyFontClass;
  36.  
  37. using MPR = MyCustomPrintLibrary
  38.   .Properties.Resources;
  39. using MPS = MyCustomPrintLibrary
  40.   .Properties.Settings;
  41.  
  42.  
  43. namespace MyCustomPrintLibrary
  44. {
  45.   public static partial class MyPrintEvent
  46.   {
  47.     internal static string
  48.       DocContents { get; set; }
  49.  
  50.     private static string
  51.       StrToPrint  { get; set; }
  52.  
  53.     private static int
  54.       CurrentPage { get; set; }
  55.  
  56.     private static bool
  57.       _firstPage = true;
  58.  
  59.     private static readonly Mutex
  60.       Mini = new Mutex(false, MPR.Mini);
  61.    
  62.  
  63.     /// <summary> Each & Every Page Printed
  64.     /// Passes thru here! PrintBlaster
  65.     /// v4.9.5.95 23-Dec-2018 by -JpE- 100%
  66.     /// </summary>
  67.     /// <param name="sender"></param>
  68.     /// <param name="eventP"></param>
  69.     public static void
  70.       PrintPageEventHandler(object sender,
  71.       PrintPageEventArgs eventP)
  72.     {
  73.       var pd = sender as PrintDocument;
  74.       if (eventP == null
  75.         || pd == null
  76.         || string.IsNullOrEmpty(
  77.         DocContents)) return;
  78.  
  79.       Mini.WaitOne();
  80.       eventP.PageSettings // trickit
  81.         .PrinterSettings =
  82.           pd.PrinterSettings;
  83.  
  84.       if(_firstPage)
  85.         StrToPrint = DocContents;
  86.  
  87.       var charsOnPage = GetCharsNum(
  88.         eventP, StrToPrint);
  89.  
  90.       MyPrintEvent2(ref eventP);
  91.  
  92.       if (!string.IsNullOrEmpty(
  93.         StrToPrint)) StrToPrint =
  94.           StrToPrint.Substring(
  95.             charsOnPage);
  96.  
  97.       eventP.HasMorePages =
  98.         StrToPrint.Length > 0;
  99.  
  100.       if (!eventP.HasMorePages)
  101.       {
  102.         _firstPage  = true;
  103.         CurrentPage = 0;
  104.         StrToPrint  = DocContents; }
  105.  
  106.       Mini.ReleaseMutex();
  107.     }
  108.  
  109.     private static void SomePages1(
  110.       ref PrintPageEventArgs p)
  111.     {
  112.       if (string.IsNullOrEmpty(
  113.         DocContents)) return;
  114.  
  115.       var page = CalculatePages(p);
  116.  
  117.       if (p.PageSettings.PrinterSettings
  118.         .FromPage > page) p.PageSettings
  119.           .PrinterSettings.FromPage = 1;
  120.  
  121.       // Correct ^v either or both if over.
  122.       if (p.PageSettings.PrinterSettings
  123.         .ToPage > page) p.PageSettings
  124.         .PrinterSettings.ToPage = page;
  125.     }
  126.  
  127.     private static int CalculatePages(
  128.       PrintPageEventArgs p)
  129.     {
  130.       var pages = 0;
  131.       var text  = DocContents;
  132.  
  133.       do
  134.       {
  135.         var chars = GetCharsNum(p, text);
  136.         ++pages;
  137.         text = text.Substring(chars);
  138.       }
  139.       while (!string.IsNullOrEmpty(text));
  140.  
  141.       return pages;
  142.     }
  143.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  144.  
  145.  
  146.   }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement