//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // MyCustomPrintLibrary.MyPrintClass.cs //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Global Access Software InTernational // Copyrighted (c) 2019 by John P. Edwards // First Created December 02, 2014 2:53 AM //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Split this section out to simplify PMP // v2.5.0.61 Nov 05 2016 05:52 AM // v2.5.0.79 Nov 12 2016 05:52 AM // Custom Brush below fixes that! // v3.6.4.81 Jan 02 2017 Final: //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Brought this one in from MyLilBlackBook: // v4.9.5.95 20-Dec-2018 PB.MyPrintEvent1 // v4.9.5.96 31-Dec Revision simplifies. // v4.9.5.98 12-Jan-2019 Moved to Project. // v5.0.5.98 12-Jan-2019 Integrate to Beta. // v5.0.5.99 15-Jan-2019 MCPL Design change. // v5.0.6.01 22-Feb-2019 Dialing it all in Now! // v5.0.6.01 02-Mar-2019 Fixedwell w/MPP Menu // items calling back across, etc. // v5.0.6.01 06-Mar-2019 // v5.0.6.02 08-Mar-2019 Batch Stuff & Debug // v5.0.6.03 14-Mar-2019 ReSetPages Call. // v5.1.7.09 24-Apr-2019 Debugged & Tested. // v5.1.7.10 25-Apr Instance-N Font stuff. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // Standard Libraries using System.Drawing.Printing; using System.IO; using System.Threading; using System.Windows.Forms; // Custom Class Aliases using MCC = MyCustomControls.CustomControl; using MPE = MyCustomPrintLibrary.MyPrintEvent; // Custom Property Aliases using MPR = MyCustomPrintLibrary .Properties.Resources; using MPS = MyCustomPrintLibrary .Properties.Settings; namespace MyCustomPrintLibrary { public static class MyPrintClass // MPC { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ public static string Open { get { using (LockOut) { return Open1; } } } // bug Not really, just follow the // model above for the rest of these. k private static string Open1 { get { return MPR.Open; } } public static string PreviewFile { get { return Preview; } } private static string Preview { get { return MPR.Preview; } } public static string PrintFile { get { return Print; } } private static string Print { get { return MPR.Print; } } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ public static bool ShowPaper { get { return Paper; } set { Paper = value;} } private static bool Paper { get { return MPS.Default.ShowBg; } set { MPS.Default.ShowBg = value; MPS.Default.Save(); } } public static byte QuitCode { get { return Code; } set { Code = value;} } private static byte Code { get { using (Mutex1) { return MPS.Default.MppExit; } } set { using (Mutex1) { MPS.Default.MppExit = value; MPS.Default.Save(); } } } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ internal static readonly Mutex LockOut = new Mutex(false, "LocalSettingsLockoutMutex"); private static readonly Mutex Mutex1 = new Mutex(false,"MyPrintClassMutex1"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ internal static PageSettings PageSet { set { PageS = value; } } private static PageSettings PageS { set { using (Mutex1) { MPS.Default.PageSet = value; MPS.Default.Save(); } } } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ internal static PrinterSettings PrintSet { set { Set1 = value; } } private static PrinterSettings Set1 { set { using (Mutex1) { //Mutex1.WaitOne(); MPS.Default.PrintSet = MPS.Default.PageSet .PrinterSettings = value; } // also ^ sets // pagesettings.printersettings. // which calls MPS.Default.Save(); //Mutex1.ReleaseMutex(); } } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ internal static PrintDocument MyPrintDoc { get { return PrintDoc; } } private static PrintDocument PrintDoc { get { return GetPrintDoc(); } } /* MyCustomControls Dox **************************** * O1 = MyOpenDialog; * R1 = MyRichTextBox; * P1 = MyPrintDialog; * P2 = MyPreviewControl; * P3 = MyPreviewDialog; * D1 = MyPrintDoc; * P4 = MyPageSetup; * M1 = MyPreviewMenuStrip; * M2 = MyColorDialog; * F0 = MyFontDialog; * S1 = MySaveDialog; **************************** */ // CheckSettings, get defaults // if nothing else is saved yet. private static PrintDocument GetPrintDoc() { //Mutex1.WaitOne(); using (Mutex1) { PrintDocument doc; using (var mcc = new MCC()) { doc = mcc.D1; if (MPS.Default.PageSet != null) doc.DefaultPageSettings = MPS.Default.PageSet; else MPS.Default.PageSet = mcc.P4.PageSettings; if (MPS.Default.PrintSet != null) doc.PrinterSettings = MPS.Default.PrintSet; else MPS.Default.PrintSet = mcc.P1.PrinterSettings; doc.PrintController = mcc.P1 .Document.PrintController; } doc.DefaultPageSettings .PrinterSettings.PrintFileName = doc.DocumentName = doc.PrinterSettings .PrintFileName = MPR.Randy; // Set EventHandlers doc.PrintPage += MPE.PrintPageEventHandler; #region Optional Events Begin/End //doc.BeginPrint += // MPE.MyBeginPrintEventHandler; //// develop as needed. //doc.EndPrint += // MPE.MyEndPrintEventHandler; #endregion //Mutex1.ReleaseMutex(); return doc; } } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ internal static void ReSetPages() { var temp = MyPrintDoc; temp.PrinterSettings.FromPage = temp.PrinterSettings.ToPage = 0; temp.PrinterSettings.PrintRange = PrintRange.AllPages; PrintSet = temp.PrinterSettings; // develop Any other "tween PrintJobs" } internal static bool IsFile(string f) { return f.Contains("\\") && f.Contains(":") && File.Exists(f); } internal static void GetContent(string file) { using (var c = new MCC()) { var rtb = c.R1; var ext = Path.GetExtension(file); if(string.IsNullOrEmpty(ext))return; if (!ext.Equals(".rtf")) { rtb.LoadFile(file, RichTextBoxStreamType.PlainText); MPE.DocContents = rtb.Text; } else {// design hack GetContent4(RTFs) rtb.LoadFile(file, RichTextBoxStreamType.RichText); MPE.DocContents = rtb.Rtf; } } } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ } }