Advertisement
GlobalAccessSoftware

MyPrintEvent2.cs

Apr 26th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.79 KB | None | 0 0
  1.  
  2.  
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // MyPrintEvent2.cs Split out 16-Mar-2019
  5. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  6. // v5.0.6.01 22-Feb-2019 Dialing all in Now!
  7. // v5.0.6.01 02-Mar-2019 FixedWell with MPP
  8. // Menu items calling back across, etc.
  9. // v5.0.6.02 08-Mar-2019 Batch Stuff & Debug
  10. // v5.0.6.03 14-Mar-2019 ReSetPages Call.
  11. // v5.0.6.03 16-Mar-2019 Split to simplify.
  12. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  13. // v5.0.6.04 25-Mar-2019 FixedWell & nearly
  14. // done. This is really working great now &
  15. // with SomePages2! Design ready: CurrentPage
  16. // PrintDialog Option to go into Selection.
  17. // Nearly all of that Logic will have to be
  18. // in ME. Since that's where BOTH
  19. // CurrentPage & Selection are or are going
  20. // to have to come from. And at some point
  21. // I will have to ReRoute or Mod or ReTest
  22. // the 2nd Instance Code in PrintForm2.cs
  23. // in PrintBlaster Deluxe. Or Call Print
  24. // Functions directly:
  25. // from Smesa to MCPL eventually maybe.
  26. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  27. // v5.0.6.04 29-Mar-2019 Tested & Clean!
  28. // v5.1.6.06 13-Apr Sel & CurPag detail.
  29. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  30.  
  31. using System.Drawing;
  32. using System.Drawing.Printing;
  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.     private static void MyPrintEvent2(
  48.       ref PrintPageEventArgs e)
  49.     {
  50.       if (_firstPage)
  51.       {
  52.         _firstPage = false;
  53.         if (e.PageSettings
  54.           .PrinterSettings.PrintRange
  55.             .Equals(PrintRange.SomePages))
  56.           SomePages1(ref e);
  57.       }
  58.  
  59.       if (e.PageSettings.PrinterSettings
  60.         .PrintRange.Equals(
  61.           PrintRange.SomePages))
  62.             SomePages2(ref e);
  63.  
  64.       if (e.PageSettings.PrinterSettings
  65.         .PrintRange.Equals(
  66.           PrintRange.AllPages))
  67.         PrintThisPageNow(e);
  68.  
  69.       if (!e.PageSettings.PrinterSettings
  70.           .PrintRange.Equals(
  71.           PrintRange.CurrentPage)
  72.        && !e.PageSettings.PrinterSettings
  73.           .PrintRange.Equals(
  74.         PrintRange.Selection)) return;
  75.  
  76.       // else is Selection, do till done.
  77.       if (!string.IsNullOrEmpty(
  78.         StrToPrint)) PrintThisPageNow(e);
  79.  
  80.       // or CurrentPage. (when applicable)
  81.       if (e.PageSettings.PrinterSettings
  82.           .PrintRange.Equals(
  83.             PrintRange.CurrentPage))
  84.         StrToPrint = "";
  85.       // CurrentPage  ^ Exits cut it short.
  86.     }
  87.  
  88.     // Perfected v5.0.6.04 25-Mar-2019 -JpE-
  89.     private static void SomePages2(
  90.       ref PrintPageEventArgs e)
  91.     {
  92.       // Skip ahead to the FromPage if needed.
  93.       while (++CurrentPage < e.PageSettings
  94.         .PrinterSettings.FromPage)
  95.           StrToPrint = StrToPrint
  96.             .Substring(GetCharsNum(
  97.               e, StrToPrint));
  98.  
  99.       PrintThisPageNow(e);
  100.  
  101.       // Print ^ from FromPage to ToPage only.
  102.       if (CurrentPage >= e.PageSettings
  103.         .PrinterSettings.ToPage)
  104.           StrToPrint = "";
  105.       // After ToPage cut it short. (Exits)
  106.     }
  107.  
  108.     private static int GetCharsNum(
  109.       PrintPageEventArgs e, string str2Prnt)
  110.     {
  111.       int charsOnPage, linesPerPage;
  112.       // Atypical
  113.       e.Graphics.MeasureString(str2Prnt,
  114.         MFC.MyFontDialog.Font,
  115.         e.MarginBounds.Size,
  116.         StringFormat.GenericTypographic,
  117.         out charsOnPage, out linesPerPage);
  118.  
  119.       return charsOnPage;
  120.     }
  121.  
  122.     private static void PrintThisPageNow(
  123.       PrintPageEventArgs e)
  124.     {
  125.       var customBrush = new SolidBrush(
  126.         MFC.MyFontDialog.Color);
  127.       try
  128.       {
  129.         e.Graphics.DrawString(
  130.           StrToPrint,
  131.           MFC.MyFontDialog.Font,
  132.           customBrush,
  133.           e.MarginBounds,
  134.           StringFormat.GenericTypographic);
  135.       }
  136.       finally { customBrush.Dispose(); }
  137.     }
  138.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  139.  
  140.  
  141. #region Other Available EventHandlers
  142.  
  143.     //public static void
  144.     //  MyBeginPrintEventHandler(
  145.     //  object sender, PrintEventArgs e)
  146.     //{
  147.     //  // todos BeginPrint if needed.
  148.  
  149.     //  const string txt =
  150.     //    "Print Job Started.";
  151.     //  MessageBox.Show(txt);
  152.     //}
  153.  
  154.     //public static void
  155.     //  MyEndPrintEventHandler(
  156.     //  object sender,
  157.     //  PrintEventArgs printEventArgs)
  158.     //{
  159.     //  // todos EndPrint if needed.
  160.     //  // what do sender and event-args
  161.     //  // contain at this point?
  162.  
  163.     //  const string txt =
  164.     //    "Print Job Completed.";
  165.     //  MessageBox.Show(txt);
  166.     //}
  167. #endregion Other Available Events
  168.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  169.  
  170.  
  171.   }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement