Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dialogboxes_printerselectbox.cs

(view source code of dialogboxes_printerselectbox.cs as plain text)

  1. using System.Linq;
  2.  
  3.  
  4. namespace RobvanderWoude
  5. {
  6. 	[System.Runtime.InteropServices.Guid( "83C1C4AF-4772-490D-B19D-8306049FB696" )]
  7. 	public interface PrinterSelectBox_Interface
  8. 	{
  9. 		[System.Runtime.InteropServices.DispId( 1 )]
  10. 		void CheckUpdate( );
  11.  
  12. 		[System.Runtime.InteropServices.DispId( 2 )]
  13. 		string Credits( );
  14.  
  15. 		[System.Runtime.InteropServices.DispId( 3 )]
  16. 		string Help( int html = 0 );
  17.  
  18. 		[System.Runtime.InteropServices.DispId( 4 )]
  19. 		string ListAllPrinters( );
  20.  
  21. 		[System.Runtime.InteropServices.DispId( 5 )]
  22. 		string ListCategories( );
  23.  
  24. 		[System.Runtime.InteropServices.DispId( 6 )]
  25. 		string ListCategory( );
  26.  
  27. 		[System.Runtime.InteropServices.DispId( 7 )]
  28. 		string ListProperties( );
  29.  
  30. 		[System.Runtime.InteropServices.DispId( 8 )]
  31. 		string SampleCode( );
  32.  
  33. 		[System.Runtime.InteropServices.DispId( 9 )]
  34. 		void Show( );
  35. 	}
  36.  
  37.  
  38. 	[System.Runtime.InteropServices.Guid( "1E59AFDD-F2CE-475A-BC3F-8A6AEA4A9B24" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )]
  39. 	public interface PrinterSelectBox_Events
  40. 	{
  41. 	}
  42.  
  43.  
  44. 	[System.Runtime.InteropServices.Guid( "732803C6-23C3-4E19-B231-AF43D946EB5B" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( PrinterSelectBox_Events ) )]
  45. 	public class PrinterSelectBox : PrinterSelectBox_Interface
  46. 	{
  47. 		#region Default Values
  48.  
  49. 		const string defaultcaptioncancel = "Cancel";
  50. 		const string defaultcaptionok = "OK";
  51. 		static readonly System.Drawing.FontFamily defaultfontfamily = System.Drawing.FontFamily.GenericSansSerif;
  52. 		const float defaultfontsize = 10;
  53. 		const PrinterCategory defaultprintercategory = PrinterCategory.All;
  54. 		const int defaulttimeout = 0;
  55. 		static readonly string defaulttitle = string.Format( "{0},  Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion );
  56. 		const int defaultwindowheight = 220;
  57. 		const int defaultwindowwidth = 400;
  58. 		const float minimumfontsize = 6;
  59. 		const float maximumfontsize = 48;
  60.  
  61. 		#endregion Default Values
  62.  
  63.  
  64. 		static System.Collections.Generic.List<string[]> allprinters = QueryPrinters( );
  65. 		static System.Collections.Generic.List<string[]> printerslist;
  66.  
  67.  
  68. 		#region Controls
  69.  
  70. 		static System.Windows.Forms.Form printerselectform;
  71. 		static System.Windows.Forms.ComboBox printersdropdown;
  72. 		static System.Windows.Forms.Label statusfield;
  73. 		static System.Windows.Forms.Label typefield;
  74. 		static System.Windows.Forms.Label wherefield;
  75. 		static System.Windows.Forms.Label commentfield;
  76. 		static System.Timers.Timer timer;
  77.  
  78. 		#endregion Controls
  79.  
  80.  
  81. 		#region Methods
  82.  
  83. 		public void CheckUpdate( )
  84. 		{
  85. 			Global.Common.ProgramInfo.CheckUpdate( );
  86. 		}
  87.  
  88.  
  89. 		public string Credits( )
  90. 		{
  91. 			return Global.Common.Credits( );
  92. 		}
  93.  
  94.  
  95. 		static string DefaultPrinter( )
  96. 		{
  97. 			string defaultprinter = string.Empty;
  98. 			string query = "SELECT * FROM Win32_Printer WHERE Default=TRUE";
  99. 			System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher( "root\\CIMV2", query );
  100. 			foreach ( System.Management.ManagementObject queryObj in searcher.Get( ) )
  101. 			{
  102. 				defaultprinter = (string) queryObj["DeviceID"];
  103. 			}
  104. 			return defaultprinter;
  105. 		}
  106.  
  107.  
  108. 		public string Help( int html = 0 )
  109. 		{
  110. 			int col1width = 0;
  111. 			int col2width = 0;
  112. 			int col3width = 0;
  113. 			int col4width = 0;
  114. 			int col5width = 0;
  115. 			string help = string.Empty;
  116. 			string linetemplate = string.Empty;
  117. 			string separatorline = string.Empty;
  118.  
  119. 			if ( html == 1 )
  120. 			{
  121. 				help += "<h1>Help for PrinterSelectBox class</h1>\n\n";
  122. 				help += "<p>Present a basic print dialog, and return the selected printer name</p>\n\n";
  123. 				help += "<h2>COM ProgID: RobvanderWoude.PrinterSelectBox</h2>\n\n";
  124. 			}
  125. 			else
  126. 			{
  127. 				help += "Help for PrinterSelectBox class\n";
  128. 				help += new string( '\u2500', help.Length ) + "\n\n";
  129. 				help += "Present a basic print dialog, and return the selected printer name\n\n\n";
  130. 				help += "COM ProgID: RobvanderWoude.PrinterSelectBox\n\n\n";
  131. 			}
  132.  
  133.  
  134. 			#region Properties
  135.  
  136. 			if ( html == 1 )
  137. 			{
  138. 				separatorline = string.Empty;
  139. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n\t<td>{3}</td>\n\t<td>{4}</td>\n</tr>\n";
  140.  
  141. 				help += "<table>\n";
  142. 				help += "<tr>\n";
  143. 				help += "\t<th colspan=\"5\">Properties (Note that all properties are string or integer, no booleans, objects or arrays)</th>\n";
  144. 				help += "</tr>\n";
  145.  
  146. 				help += "<tr>\n";
  147. 				help += "\t<th>Property Name</th>\n";
  148. 				help += "\t<th>Description</th>\n";
  149. 				help += "\t<th>Mandatory</th>\n";
  150. 				help += "\t<th>Read-Only</th>\n";
  151. 				help += "\t<th>Default (Allowed) Values</th>\n";
  152. 				help += "</tr>\n";
  153. 			}
  154. 			else
  155. 			{
  156. 				col1width = 16;
  157. 				col2width = 50;
  158. 				col3width = 9;
  159. 				col4width = 9;
  160. 				col5width = 44;
  161.  
  162. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u253C" + new string( '\u2500', 2 + col4width ) + "\u253C" + new string( '\u2500', 2 + col5width ) + "\u2524\n";
  163. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502 {3,-" + col4width.ToString( ) + "} \u2502 {4,-" + col5width.ToString( ) + "} \u2502\n";
  164.  
  165. 				help += "\u250C" + new string( '\u2500', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2510\n";
  166. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  167. 				help += string.Format( "\u2502 {0,-" + ( 12 + col1width + col2width + col3width + col4width + col5width ).ToString( ) + "} \u2502\n", "Properties        (Note that all properties are string or integer, no booleans, objects or arrays)" );
  168. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  169. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2564" + new string( '\u2550', 2 + col4width ) + "\u2564" + new string( '\u2550', 2 + col5width ) + "\u2561\n";
  170. 				help += string.Format( linetemplate, "Property Name", "Description", "Mandatory", "Read-Only", "Default (Allowed) Values" );
  171. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u256A" + new string( '\u2550', 2 + col4width ) + "\u256A" + new string( '\u2550', 2 + col5width ) + "\u2561\n";
  172. 			}
  173.  
  174. 			help += HelpTableRow( linetemplate, "captioncancel", Global.Common.Help.captioncancel, "no", "no", defaultcaptioncancel, html );
  175. 			help += separatorline;
  176.  
  177. 			help += HelpTableRow( linetemplate, "captionok", Global.Common.Help.captionok, "no", "no", defaultcaptionok, html );
  178. 			help += separatorline;
  179.  
  180. 			help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html );
  181. 			help += separatorline;
  182.  
  183. 			help += HelpTableRow( linetemplate, "defaultprinter", "The current default printer name", "N/A", "YES", "", html );
  184. 			help += separatorline;
  185.  
  186. 			help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html );
  187. 			help += separatorline;
  188.  
  189. 			help += HelpTableRow( linetemplate, "fontfamily", Global.Common.Help.fontfamily, "no", "no", defaultfontfamily.Name, html );
  190. 			help += separatorline;
  191.  
  192. 			help += HelpTableRow( linetemplate, "fontsize", Global.Common.Help.fontsize, "no", "no", string.Format( "{0} ({1}..{2})", defaultfontsize, minimumfontsize, maximumfontsize ), html );
  193. 			help += separatorline;
  194.  
  195. 			help += HelpTableRow( linetemplate, "left", Global.Common.Help.left, "no", "no", "Centered (0..screen width - windowwidth)", html );
  196. 			help += separatorline;
  197.  
  198. 			help += HelpTableRow( linetemplate, "literal", Global.Common.Help.literal, "no", "no", "0: interpret \"\\t\" as tab and \"\\n\" as newline", html );
  199. 			help += separatorline;
  200.  
  201. 			help += HelpTableRow( linetemplate, "localizecaptions", Global.Common.Help.localizecaptions, "no", "no", "0: English captions", html );
  202. 			help += separatorline;
  203.  
  204. 			help += HelpTableRow( linetemplate, "modal", Global.Common.Help.modal, "no", "no", "1: always on top", html );
  205. 			help += separatorline;
  206.  
  207. 			help += HelpTableRow( linetemplate, "preselected", "The initially preselected printer", "no", "no", "default printer or first in list", html );
  208. 			help += separatorline;
  209.  
  210. 			help += HelpTableRow( linetemplate, "printercategory", "Show only printers from this category", "no", "no", string.Format( "{0} ({1})", defaultprintercategory, ListCategories( ).Replace( ";", ", " ) ), html );
  211. 			help += separatorline;
  212.  
  213. 			help += HelpTableRow( linetemplate, "selectedprinter", "The printer that was selected when the \"OK\" button was clicked or timeout elapsed; if \"Cancel\" was clicked, selectedprinter is the default printer", "N/A", "YES", "", html );
  214. 			help += separatorline;
  215.  
  216. 			help += HelpTableRow( linetemplate, "timeout", Global.Common.Help.timeout, "no", "no", defaulttimeout.ToString( ), html );
  217. 			help += separatorline;
  218.  
  219. 			help += HelpTableRow( linetemplate, "timeoutelapsed", Global.Common.Help.timeoutelapsed, "N/A", "YES", "", html );
  220. 			help += separatorline;
  221.  
  222. 			help += HelpTableRow( linetemplate, "title", Global.Common.Help.title, "no", "no", defaulttitle, html );
  223. 			help += separatorline;
  224.  
  225. 			help += HelpTableRow( linetemplate, "top", Global.Common.Help.top, "no", "no", "Centered (0..screen height - windowheight)", html );
  226. 			help += separatorline;
  227.  
  228. 			help += HelpTableRow( linetemplate, "Version", Global.Common.Help.version, "N/A", "YES", "", html );
  229. 			help += separatorline;
  230.  
  231. 			help += HelpTableRow( linetemplate, "windowheight", Global.Common.Help.windowheight, "no", "no", string.Format( "{0} ({0}..screenheight)", defaultwindowheight ), html );
  232. 			help += separatorline;
  233.  
  234. 			help += HelpTableRow( linetemplate, "windowwidth", Global.Common.Help.windowwidth, "no", "no", string.Format( "{0} ({0}..screenwidth)", defaultwindowwidth ), html );
  235.  
  236. 			if ( html == 1 )
  237. 			{
  238. 				help += "</table>\n\n\n";
  239. 			}
  240. 			else
  241. 			{
  242. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2534" + new string( '\u2500', 2 + col4width ) + "\u2534" + new string( '\u2500', 2 + col5width ) + "\u2518\n\n\n";
  243. 			}
  244.  
  245. 			#endregion Properties
  246.  
  247.  
  248. 			#region Methods
  249.  
  250. 			if ( html == 1 )
  251. 			{
  252. 				separatorline = string.Empty;
  253. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n</tr>\n";
  254.  
  255. 				help += "<table>\n";
  256. 				help += "<tr>\n";
  257. 				help += "\t<th colspan=\"3\">Methods</th>\n";
  258. 				help += "</tr>\n";
  259.  
  260. 				help += "<tr>\n";
  261. 				help += "\t<th>Method Name</th>\n";
  262. 				help += "\t<th>Description</th>\n";
  263. 				help += "\t<th>Requirements</th>\n";
  264. 				help += "</tr>\n";
  265. 			}
  266. 			else
  267. 			{
  268. 				col1width = 16;
  269. 				col2width = 74;
  270. 				col3width = 44;
  271.  
  272. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u2524\n";
  273. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502\n";
  274.  
  275. 				help += "\u250C" + new string( '\u2500', 8 + col1width + col2width + col3width ) + "\u2510\n";
  276. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  277. 				help += string.Format( "\u2502 {0,-" + ( 6 + col1width + col2width + col3width ).ToString( ) + "} \u2502\n", "Methods" );
  278. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  279. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  280. 				help += string.Format( linetemplate, "Method Name", "Description", "Requirements" );
  281. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  282. 			}
  283.  
  284. 			help += HelpTableRow( linetemplate, "CheckUpdate", Global.Common.Help._checkupdate, "", html );
  285. 			help += separatorline;
  286.  
  287. 			help += HelpTableRow( linetemplate, "Credits", Global.Common.Help._credits, "", html );
  288. 			help += separatorline;
  289.  
  290. 			help += HelpTableRow( linetemplate, "Help", Global.Common.Help._help, "", html );
  291. 			help += separatorline;
  292.  
  293. 			help += HelpTableRow( linetemplate, "ListAllPrinters", "Returns as list of all printers", "", html );
  294. 			help += separatorline;
  295.  
  296. 			help += HelpTableRow( linetemplate, "ListCategories", "Returns as list of available printer categories", "", html );
  297. 			help += separatorline;
  298.  
  299. 			help += HelpTableRow( linetemplate, "ListCategory", "Returns as list of all printers in the selected category", "", html );
  300. 			help += separatorline;
  301.  
  302. 			help += HelpTableRow( linetemplate, "ListProperties", Global.Common.Help._listproperties, "", html );
  303. 			help += separatorline;
  304.  
  305. 			help += HelpTableRow( linetemplate, "SampleCode", Global.Common.Help._samplecode, "", html );
  306. 			help += separatorline;
  307.  
  308. 			help += HelpTableRow( linetemplate, "Show", "Presents a basic print dialog based on the current property values, and if \"OK\" is clicked, saves last selected printer name in the \"selectedprinter\" property (if \"Cancel\" is clicked, \"selectedprinter\" is default printer).", "", html );
  309.  
  310. 			if ( html == 1 )
  311. 			{
  312. 				help += "</table>\n\n\n";
  313. 			}
  314. 			else
  315. 			{
  316. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2518\n\n\n";
  317. 			}
  318.  
  319. 			#endregion Methods
  320.  
  321.  
  322. 			#region Example
  323.  
  324. 			if ( html == 1 )
  325. 			{
  326. 				help += "<h2>VBScript usage example:</h2>\n\n<pre>";
  327. 			}
  328. 			else
  329. 			{
  330. 				help += "VBScript usage example:\n";
  331. 				help += new string( '\u2500', 23 ) + "\n\n";
  332. 			}
  333.  
  334. 			help += SampleCode( );
  335.  
  336. 			if ( html == 1 )
  337. 			{
  338. 				help += "</pre>";
  339. 			}
  340.  
  341. 			help += "\n\n";
  342.  
  343. 			#endregion Example
  344.  
  345.  
  346. 			help = help.Replace( "\n", System.Environment.NewLine );
  347. 			return help;
  348. 		}
  349.  
  350.  
  351. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, int html )
  352. 		{
  353. 			if ( html == 1 )
  354. 			{
  355. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text );
  356. 			}
  357. 			else
  358. 			{
  359. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, "", "" );
  360. 			}
  361. 		}
  362.  
  363.  
  364. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, string col4text, string col5text, int html )
  365. 		{
  366. 			if ( html == 1 )
  367. 			{
  368. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text, col4text, col5text );
  369. 			}
  370. 			else
  371. 			{
  372. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, col4text, col5text );
  373. 			}
  374. 		}
  375.  
  376.  
  377. 		public string ListAllPrinters( )
  378. 		{
  379. 			return string.Join( ";", allprinters.Select( p => p[0] ).ToArray( ) );
  380. 		}
  381.  
  382.  
  383. 		public string ListCategories( )
  384. 		{
  385. 			return string.Join( ";", System.Enum.GetNames( typeof( PrinterCategory ) ) );
  386. 		}
  387.  
  388.  
  389. 		public string ListCategory( )
  390. 		{
  391. 			return string.Join( ";", printerslist.Select( p => p[0] ).ToArray( ) );
  392. 		}
  393.  
  394.  
  395. 		public string ListProperties( )
  396. 		{
  397. 			return Global.Common.Lists.Properties( this );
  398. 		}
  399.  
  400.  
  401. 		static System.Collections.Generic.List<string[]> QueryPrinters( )
  402. 		{
  403. 			System.Collections.Generic.List<string[]> printers = new System.Collections.Generic.List<string[]>( );
  404.  
  405. 			string query = "SELECT * FROM Win32_Printer";
  406. 			System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher( "root\\CIMV2", query );
  407. 			foreach ( System.Management.ManagementObject queryObj in searcher.Get( ) )
  408. 			{
  409. 				string printer = (string) queryObj["DeviceID"];
  410. 				uint printerstatus = System.Convert.ToUInt32( queryObj["ExtendedPrinterStatus"] );
  411. 				string printertype = (string) queryObj["DriverName"];
  412. 				string printerlocation = (string) queryObj["Location"];
  413. 				string printerport = (string) queryObj["PortName"];
  414. 				string printercomment = (string) queryObj["Comment"];
  415. 				bool isdefault = (bool) queryObj["Default"];
  416. 				bool islocal = (bool) queryObj["Local"];
  417. 				bool isnetwork = (bool) queryObj["Network"];
  418. 				bool isphysical = ( queryObj["PrintProcessor"].ToString( ).ToLower( ) != "winprint" );
  419. 				string[] printerproperties = new string[9];
  420. 				printerproperties[0] = printer;
  421. 				printerproperties[1] = ( (WMIPrinterStatus) printerstatus ).ToString( );
  422. 				printerproperties[2] = printertype;
  423. 				if ( string.IsNullOrWhiteSpace( printerlocation ) )
  424. 				{
  425. 					printerproperties[3] = printerport;
  426. 				}
  427. 				else
  428. 				{
  429. 					printerproperties[3] = printerlocation;
  430. 				}
  431. 				printerproperties[4] = printercomment;
  432. 				printerproperties[5] = ( isdefault ? "1" : "0" );
  433. 				printerproperties[6] = ( islocal ? "1" : "0" );
  434. 				printerproperties[7] = ( isnetwork ? "1" : "0" );
  435. 				printerproperties[8] = ( isphysical ? "1" : "0" );
  436. 				printers.Add( printerproperties );
  437. 			}
  438.  
  439. 			printers.Sort( ( x, y ) => string.Compare( x[0], y[0] ) );
  440.  
  441. 			return printers;
  442. 		}
  443.  
  444.  
  445. 		public string SampleCode( )
  446. 		{
  447. 			string code = "Set objPrinterSelectBox = CreateObject( \"RobvanderWoude.PrinterSelectBox\" )\n\n";
  448. 			code += "With objPrinterSelectBox\n";
  449. 			code += "\t.printercategory = \"Physical\"\n";
  450. 			code += "\t.top             = 200\n";
  451. 			code += "\t.left            = 300\n";
  452. 			code += "\t.timeout         = 15\n";
  453. 			code += "\t.title           = \"Select a Physical Printer\"\n";
  454. 			code += "\tWScript.Echo\n";
  455. 			code += "\tWScript.Echo \"Printers to choose from:\"\n";
  456. 			code += "\tWScript.Echo \"========================\"\n";
  457. 			code += "\tWScript.Echo .ListCategory( )\n";
  458. 			code += "\tWScript.Echo\n";
  459. 			code += "\t.Show\n";
  460. 			code += "\tWScript.Echo \"Selected printer: \" & .selectedprinter\n";
  461. 			code += "\tWScript.Echo\n";
  462. 			code += "\tWScript.Echo \"Default printer:  \" & .defaultprinter\n";
  463. 			code += "\tWScript.Echo\n";
  464. 			code += "\tWScript.Echo .ListProperties( )\n";
  465. 			code += "End With\n\n";
  466. 			code += "Set objPrinterSelectBox = Nothing";
  467. 			return code;
  468. 		}
  469.  
  470.  
  471. 		[System.STAThread]
  472. 		public void Show( )
  473. 		{
  474. 			#region Check Printers List
  475.  
  476. 			if ( printerslist.Count == 0 )
  477. 			{
  478. 				_debuginfo.Add( string.Format( "{0}Printers list for category \"{1}\" is empty, using category \"All\" with {2} printers instead", timestamp, printercategory, allprinters.Count ) );
  479. 				printerslist = allprinters;
  480. 				_printercategory = PrinterCategory.All;
  481. 			}
  482.  
  483. 			#endregion Check Printers List
  484.  
  485.  
  486. 			#region Timer
  487.  
  488. 			_timeoutelapsed = false;
  489. 			if ( timeout > 0 )
  490. 			{
  491. 				timer = new System.Timers.Timer( );
  492. 				timer.Elapsed += new System.Timers.ElapsedEventHandler( PrinterSelectBox_Timer_Elapsed );
  493. 				timer.Interval = timeout * 1000;
  494. 				timer.Start( );
  495. 				_debuginfo.Add( timestamp + "Timer started with interval " + timeout.ToString( ) );
  496. 			}
  497.  
  498. 			#endregion Timer
  499.  
  500.  
  501. 			#region Build Form
  502.  
  503. 			try
  504. 			{
  505. 				#region Form
  506.  
  507. 				printerselectform = new System.Windows.Forms.Form( );
  508. 				System.Drawing.Size size = new System.Drawing.Size( windowwidth, windowheight );
  509. 				printerselectform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  510. 				printerselectform.MaximizeBox = false;
  511. 				printerselectform.MinimizeBox = false;
  512. 				printerselectform.ClientSize = size;
  513. 				printerselectform.Text = title;
  514. 				printerselectform.Font = new System.Drawing.Font( fontfamily, fontsize );
  515. 				printerselectform.TopLevel = topmost;
  516. 				if ( left < 0 || top < 0 )
  517. 				{
  518. 					printerselectform.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  519. 				}
  520. 				else
  521. 				{
  522. 					printerselectform.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  523. 					printerselectform.Location = new System.Drawing.Point( left, top );
  524. 				}
  525. 				_debuginfo.Add( timestamp + "Window width: " + windowwidth );
  526. 				_debuginfo.Add( timestamp + "Window height: " + windowheight );
  527. 				_debuginfo.Add( timestamp + "Window location: " + printerselectform.Location.X + "," + printerselectform.Location.Y );
  528.  
  529. 				#endregion Form
  530.  
  531.  
  532. 				#region Label 'Name'
  533.  
  534. 				System.Windows.Forms.Label labelName = new System.Windows.Forms.Label( );
  535. 				labelName.Size = new System.Drawing.Size( 70, 20 );
  536. 				labelName.Location = new System.Drawing.Point( 10, 27 );
  537. 				labelName.Text = "Name:";
  538. 				printerselectform.Controls.Add( labelName );
  539.  
  540. 				#endregion Label 'Name'
  541.  
  542.  
  543. 				#region Dropdown
  544.  
  545. 				printersdropdown = new System.Windows.Forms.ComboBox( );
  546. 				printersdropdown.Size = new System.Drawing.Size( size.Width - 100, 25 );
  547. 				printersdropdown.Location = new System.Drawing.Point( 90, 25 );
  548. 				printersdropdown.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
  549. 				printersdropdown.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
  550. 				printersdropdown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  551. 				foreach ( string[] printer in printerslist )
  552. 				{
  553. 					printersdropdown.Items.Add( printer[0] );
  554. 				}
  555. 				printersdropdown.Update( );
  556. 				printersdropdown.SelectedIndex = _preselectedindex;
  557. 				printersdropdown.SelectedIndexChanged += new System.EventHandler( PrinterSelectBox_Combobox_SelectedIndexChanged );
  558. 				printerselectform.Controls.Add( printersdropdown );
  559.  
  560. 				#endregion Dropdown
  561.  
  562.  
  563. 				#region Label 'Status'
  564.  
  565. 				System.Windows.Forms.Label labelStatus = new System.Windows.Forms.Label( );
  566. 				labelStatus.Size = new System.Drawing.Size( 70, 20 );
  567. 				labelStatus.Location = new System.Drawing.Point( 10, 57 );
  568. 				labelStatus.Text = "Status:";
  569. 				printerselectform.Controls.Add( labelStatus );
  570.  
  571. 				#endregion Label 'Status'
  572.  
  573.  
  574. 				#region Printer Status Field
  575.  
  576. 				statusfield = new System.Windows.Forms.Label( );
  577. 				statusfield.Size = new System.Drawing.Size( size.Width - 10 - 80, 20 );
  578. 				statusfield.Location = new System.Drawing.Point( 90, 57 );
  579. 				statusfield.Text = "Status Value";
  580. 				printerselectform.Controls.Add( statusfield );
  581.  
  582. 				#endregion Printer Status Field
  583.  
  584.  
  585. 				#region Label 'Type'
  586.  
  587. 				System.Windows.Forms.Label labelType = new System.Windows.Forms.Label( );
  588. 				labelType.Size = new System.Drawing.Size( 70, 20 );
  589. 				labelType.Location = new System.Drawing.Point( 10, 82 );
  590. 				labelType.Text = "Type:";
  591. 				printerselectform.Controls.Add( labelType );
  592.  
  593. 				#endregion Label 'Type'
  594.  
  595.  
  596. 				#region Printer Type Description
  597.  
  598. 				typefield = new System.Windows.Forms.Label( );
  599. 				typefield.Size = new System.Drawing.Size( size.Width - 10 - 80, 20 );
  600. 				typefield.Location = new System.Drawing.Point( 90, 82 );
  601. 				typefield.Text = "Type Value";
  602. 				printerselectform.Controls.Add( typefield );
  603.  
  604. 				#endregion Printer Type Description
  605.  
  606.  
  607. 				#region Label 'Where'
  608.  
  609. 				System.Windows.Forms.Label labelWhere = new System.Windows.Forms.Label( );
  610. 				labelWhere.Size = new System.Drawing.Size( 70, 20 );
  611. 				labelWhere.Location = new System.Drawing.Point( 10, 107 );
  612. 				labelWhere.Text = "Where:";
  613. 				printerselectform.Controls.Add( labelWhere );
  614.  
  615. 				#endregion Label 'Where'
  616.  
  617.  
  618. 				#region Printer Location Field
  619.  
  620. 				wherefield = new System.Windows.Forms.Label( );
  621. 				wherefield.Size = new System.Drawing.Size( size.Width - 10 - 80, 20 );
  622. 				wherefield.Location = new System.Drawing.Point( 90, 107 );
  623. 				wherefield.Text = "Where Value";
  624. 				printerselectform.Controls.Add( wherefield );
  625.  
  626. 				#endregion Printer Location Field
  627.  
  628.  
  629. 				#region Label 'Comment'
  630.  
  631. 				System.Windows.Forms.Label labelComment = new System.Windows.Forms.Label( );
  632. 				labelComment.Size = new System.Drawing.Size( 70, 20 );
  633. 				labelComment.Location = new System.Drawing.Point( 10, 132 );
  634. 				labelComment.Text = "Comment:";
  635. 				printerselectform.Controls.Add( labelComment );
  636.  
  637. 				#endregion Label 'Comment'
  638.  
  639.  
  640. 				#region Comment Field
  641.  
  642. 				commentfield = new System.Windows.Forms.Label( );
  643. 				commentfield.Size = new System.Drawing.Size( size.Width - 10 - 80, 20 );
  644. 				commentfield.Location = new System.Drawing.Point( 90, 132 );
  645. 				commentfield.Text = "Comment Value";
  646. 				printerselectform.Controls.Add( commentfield );
  647.  
  648. 				#endregion Comment Field
  649.  
  650.  
  651. 				#region Buttons
  652.  
  653. 				System.Windows.Forms.Button okButton = new System.Windows.Forms.Button( );
  654. 				okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  655. 				okButton.Name = "okButton";
  656. 				okButton.Size = new System.Drawing.Size( 80, 25 );
  657. 				okButton.Text = captionok;
  658. 				okButton.Location = new System.Drawing.Point( size.Width / 2 - 10 - 80, 175 );
  659. 				printerselectform.Controls.Add( okButton );
  660.  
  661. 				System.Windows.Forms.Button cancelButton = new System.Windows.Forms.Button( );
  662. 				cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  663. 				cancelButton.Name = "cancelButton";
  664. 				cancelButton.Size = new System.Drawing.Size( 80, 25 );
  665. 				cancelButton.Text = captioncancel;
  666. 				cancelButton.Location = new System.Drawing.Point( size.Width / 2 + 10, 175 );
  667. 				printerselectform.Controls.Add( cancelButton );
  668.  
  669. 				#endregion Buttons
  670.  
  671.  
  672. 				statusfield.Text = printerslist[_preselectedindex][1];
  673. 				typefield.Text = printerslist[_preselectedindex][2];
  674. 				wherefield.Text = printerslist[_preselectedindex][3];
  675. 				commentfield.Text = printerslist[_preselectedindex][4];
  676.  
  677.  
  678. 				printerselectform.AcceptButton = okButton;  // OK on Enter
  679. 				printerselectform.CancelButton = cancelButton; // Cancel on Esc
  680. 				printerselectform.Activate( );
  681. 			}
  682. 			catch ( System.Exception e )
  683. 			{
  684. 				_errors.Add( Global.Common.TimeStamp( ) + "Error while trying to build form: " + e.Message );
  685. 			}
  686.  
  687. 			#endregion Build Form
  688.  
  689.  
  690. 			#region Show Dialog and Return Result
  691.  
  692. 			try
  693. 			{
  694. 				System.Windows.Forms.DialogResult result = printerselectform.ShowDialog( );
  695. 				if ( _timeoutelapsed )
  696. 				{
  697. 					_debuginfo.Add( timestamp + "Timeout elapsed" );
  698. 				}
  699. 				else if ( result == System.Windows.Forms.DialogResult.Cancel )
  700. 				{
  701. 					_debuginfo.Add( timestamp + "Cancelled, using default printer" );
  702. 					_selectedprinter = defaultprinter;
  703. 				}
  704. 				else // OK
  705. 				{
  706. 					_selectedprinter = printersdropdown.Text;
  707. 				}
  708. 				_debuginfo.Add( timestamp + "Selected printer: " + selectedprinter );
  709. 			}
  710. 			catch ( System.Exception e )
  711. 			{
  712. 				_errors.Add( Global.Common.TimeStamp( ) + "Error while trying to show dialog: " + e.Message );
  713. 			}
  714.  
  715. 			#endregion Show Dialog and Return Result
  716. 		}
  717.  
  718.  
  719. 		public void UpdatePrinterSelectBoxFields( )
  720. 		{
  721. 			try
  722. 			{
  723. 				string printername = printersdropdown.Text;
  724. 				statusfield.Text = printerslist.Where( p => p[0] == printername ).First( )[1];
  725. 				typefield.Text = printerslist.Where( p => p[0] == printername ).First( )[2];
  726. 				wherefield.Text = printerslist.Where( p => p[0] == printername ).First( )[3];
  727. 				commentfield.Text = printerslist.Where( p => p[0] == printername ).First( )[4];
  728. 			}
  729. 			catch ( System.Exception e )
  730. 			{
  731. 				_errors.Add( Global.Common.TimeStamp( ) + "Error updating dialog fields: " + e.Message );
  732. 			}
  733. 		}
  734.  
  735. 		#endregion Methods
  736.  
  737.  
  738. 		#region Properties
  739.  
  740. 		private string _captioncancel = defaultcaptioncancel;
  741. 		[System.Runtime.InteropServices.ComVisible( true )]
  742. 		public string captioncancel
  743. 		{
  744. 			get
  745. 			{
  746. 				if ( _localizecaptions && _captioncancel == defaultcaptioncancel )
  747. 				{
  748. 					_captioncancel = Global.Common.Localization.Load( "user32.dll", 801, defaultcaptioncancel );
  749. 				}
  750. 				return _captioncancel;
  751. 			}
  752. 			set
  753. 			{
  754. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 )
  755. 				{
  756. 					_captioncancel = defaultcaptioncancel;
  757. 				}
  758. 				else
  759. 				{
  760. 					_captioncancel = value;
  761. 				}
  762. 				//_debuginfo.Add()
  763. 			}
  764. 		}
  765.  
  766.  
  767. 		private string _captionok = defaultcaptionok;
  768. 		[System.Runtime.InteropServices.ComVisible( true )]
  769. 		public string captionok
  770. 		{
  771. 			get
  772. 			{
  773. 				if ( _localizecaptions && _captionok == defaultcaptionok )
  774. 				{
  775. 					_captionok = Global.Common.Localization.Load( "user32.dll", 800, defaultcaptionok );
  776. 				}
  777. 				return _captionok;
  778. 			}
  779. 			set
  780. 			{
  781. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 )
  782. 				{
  783. 					_captionok = defaultcaptionok;
  784. 				}
  785. 				else
  786. 				{
  787. 					_captionok = value;
  788. 				}
  789. 			}
  790. 		}
  791.  
  792.  
  793. 		private System.Collections.Generic.List<string> _debuginfo = new System.Collections.Generic.List<string>( );
  794. 		[System.Runtime.InteropServices.ComVisible( true )]
  795. 		public string debuginfo
  796. 		{
  797. 			get
  798. 			{
  799. 				return string.Join( "\n", _debuginfo.ToArray( ) );
  800. 			}
  801. 		}
  802.  
  803.  
  804. 		private string _defaultprinter = DefaultPrinter( );
  805. 		[System.Runtime.InteropServices.ComVisible( true )]
  806. 		public string defaultprinter
  807. 		{
  808. 			get
  809. 			{
  810. 				return _defaultprinter;
  811. 			}
  812. 		}
  813.  
  814.  
  815. 		private System.Collections.Generic.List<string> _errors = new System.Collections.Generic.List<string>( );
  816. 		[System.Runtime.InteropServices.ComVisible( true )]
  817. 		public string errors
  818. 		{
  819. 			get
  820. 			{
  821. 				return string.Join( "\n", _errors.ToArray( ) );
  822. 			}
  823. 		}
  824.  
  825.  
  826. 		private System.Drawing.FontFamily _fontfamily = defaultfontfamily;
  827. 		[System.Runtime.InteropServices.ComVisible( true )]
  828. 		public string fontfamily
  829. 		{
  830. 			get
  831. 			{
  832. 				return _fontfamily.Name;
  833. 			}
  834. 			set
  835. 			{
  836. 				_fontfamily = Global.Common.Validate.FontFamily( value, defaultfontfamily );
  837. 			}
  838. 		}
  839.  
  840.  
  841. 		private float _fontsize = defaultfontsize;
  842. 		[System.Runtime.InteropServices.ComVisible( true )]
  843. 		public int fontsize
  844. 		{
  845. 			get
  846. 			{
  847. 				return System.Convert.ToInt32( _fontsize );
  848. 			}
  849. 			set
  850. 			{
  851. 				_fontsize = System.Convert.ToSingle( value ).LimitToRange( minimumfontsize, maximumfontsize );
  852. 			}
  853. 		}
  854.  
  855.  
  856. 		private int _left = -1;
  857. 		[System.Runtime.InteropServices.ComVisible( true )]
  858. 		public int left
  859. 		{
  860. 			get
  861. 			{
  862. 				return _left;
  863. 			}
  864. 			set
  865. 			{
  866. 				if ( value < -1 )
  867. 				{
  868. 					_left = 0;
  869. 				}
  870. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth )
  871. 				{
  872. 					_left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth;
  873. 				}
  874. 				else
  875. 				{
  876. 					_left = value;
  877. 				}
  878. 			}
  879. 		}
  880.  
  881.  
  882. 		private bool _literal = false;
  883. 		[System.Runtime.InteropServices.ComVisible( true )]
  884. 		public int literal
  885. 		{
  886. 			get
  887. 			{
  888. 				return ( _literal ? 1 : 0 );
  889. 			}
  890. 			set
  891. 			{
  892. 				_literal = ( value == 1 );
  893. 			}
  894. 		}
  895.  
  896.  
  897. 		private bool _localizecaptions = false;
  898. 		[System.Runtime.InteropServices.ComVisible( true )]
  899. 		public int localizecaptions
  900. 		{
  901. 			get
  902. 			{
  903. 				return ( _localizecaptions ? 1 : 0 );
  904. 			}
  905. 			set
  906. 			{
  907. 				_localizecaptions = ( value == 1 );
  908. 			}
  909. 		}
  910.  
  911.  
  912. 		private bool topmost = true;
  913. 		[System.Runtime.InteropServices.ComVisible( true )]
  914. 		public int modal
  915. 		{
  916. 			get
  917. 			{
  918. 				return ( topmost ? 1 : 0 );
  919. 			}
  920. 			set
  921. 			{
  922. 				topmost = ( value == 1 );
  923. 			}
  924. 		}
  925.  
  926.  
  927. 		private int _preselectedindex = allprinters.Select( p => p[0] ).ToList<string>( ).IndexOf( DefaultPrinter( ) );
  928. 		[System.Runtime.InteropServices.ComVisible( true )]
  929. 		public string preselected
  930. 		{
  931. 			get
  932. 			{
  933. 				return printerslist[_preselectedindex][0];
  934. 			}
  935. 			set
  936. 			{
  937. 				if ( int.TryParse( value, out _preselectedindex ) )
  938. 				{
  939. 					_debuginfo.Add( timestamp + "Preselected is numeric, trying to use it as index" );
  940. 					if ( _preselectedindex < 0 )
  941. 					{
  942. 						_debuginfo.Add( timestamp + "Preselected < 0, using index 0 instead" );
  943. 						_preselectedindex = 0;
  944. 					}
  945. 					if ( _preselectedindex >= printerslist.Count )
  946. 					{
  947. 						_debuginfo.Add( timestamp + "Preselected > printers count, using index 0 instead" );
  948. 						_preselectedindex = 0;
  949. 					}
  950. 					else
  951. 					{
  952. 						_debuginfo.Add( timestamp + "Preselected is a valid index" );
  953. 					}
  954. 				}
  955. 				else
  956. 				{
  957. 					_debuginfo.Add( timestamp + "Preselected: " + value );
  958. 					if ( printerslist.Select( p => p[0] ).ToList<string>( ).Contains( value ) ) // first check for full printer name match
  959. 					{
  960. 						_debuginfo.Add( timestamp + "Full printer name match" );
  961. 						_preselectedindex = printerslist.FindIndex( p => p[0].Equals( value, System.StringComparison.InvariantCultureIgnoreCase ) );
  962. 					}
  963. 					else if ( printerslist.Where( p => p[0].ToUpper( ).StartsWith( value.ToUpper( ) ) ).Any( ) ) // if not, try a partial printer name match at begin of the name
  964. 					{
  965. 						_debuginfo.Add( timestamp + "Partial printer name match (startswith)" );
  966. 						_preselectedindex = printerslist.FindIndex( p => p[0].ToUpper( ).StartsWith( value.ToUpper( ) ) );
  967. 					}
  968. 					else if ( printerslist.Where( p => p[0].ToUpper( ).Contains( value.ToUpper( ) ) ).Any( ) ) // if not, try a partial printer name match anywhere in the name
  969. 					{
  970. 						_debuginfo.Add( timestamp + "Partial printer name match (anywhere)" );
  971. 						_preselectedindex = printerslist.FindIndex( p => p[0].ToUpper( ).Contains( value.ToUpper( ) ) );
  972. 					}
  973. 					else if ( printerslist.Select( p => p[2] ).ToList<string>( ).Contains( value ) ) // if not, check for full driver name match
  974. 					{
  975. 						_debuginfo.Add( timestamp + "Full driver name match" );
  976. 						_preselectedindex = printerslist.FindIndex( p => p[2].Equals( value, System.StringComparison.InvariantCultureIgnoreCase ) );
  977. 					}
  978. 					else if ( printerslist.Where( p => p[2].ToUpper( ).StartsWith( value.ToUpper( ) ) ).Any( ) ) // if not, try a partial driver name match at begin of the name
  979. 					{
  980. 						_debuginfo.Add( timestamp + "Partial driver name match (startswith)" );
  981. 						_preselectedindex = printerslist.FindIndex( p => p[2].ToUpper( ).StartsWith( value.ToUpper( ) ) );
  982. 					}
  983. 					else if ( printerslist.Where( p => p[2].ToUpper( ).Contains( value.ToUpper( ) ) ).Any( ) ) // if not, try a partial driver name match anywhere in the name
  984. 					{
  985. 						_debuginfo.Add( timestamp + "Partial driver name match (anywhere)" );
  986. 						_preselectedindex = printerslist.FindIndex( p => p[2].ToUpper( ).Contains( value.ToUpper( ) ) );
  987. 					}
  988. 					else // or just stick with the first printer in the list
  989. 					{
  990. 						_debuginfo.Add( timestamp + "No match, using index 0" );
  991. 						_preselectedindex = 0;
  992. 					}
  993. 				}
  994. 				_debuginfo.Add( timestamp + "Preselected printer: " + preselected );
  995. 			}
  996. 		}
  997.  
  998.  
  999. 		private static PrinterCategory _printercategory = defaultprintercategory;
  1000. 		[System.Runtime.InteropServices.ComVisible( true )]
  1001. 		public string printercategory
  1002. 		{
  1003. 			get
  1004. 			{
  1005. 				return _printercategory.ToString( );
  1006. 			}
  1007. 			set
  1008. 			{
  1009. 				_debuginfo.Add( timestamp + "Trying to match \"" + value + "\" to a printer category" );
  1010. 				if ( System.Enum.TryParse( value, true, out PrinterCategory category ) )
  1011. 				{
  1012. 					switch ( category )
  1013. 					{
  1014. 						case PrinterCategory.All:
  1015. 							_printercategory = PrinterCategory.All;
  1016. 							printerslist = allprinters;
  1017. 							break;
  1018. 						case PrinterCategory.Local:
  1019. 							_printercategory = PrinterCategory.Local;
  1020. 							printerslist = allprinters.Where( p => p[6] == "1" ).ToList<System.String[]>( );
  1021. 							break;
  1022. 						case PrinterCategory.Network:
  1023. 							_printercategory = PrinterCategory.Network;
  1024. 							printerslist = allprinters.Where( p => p[7] == "1" ).ToList<System.String[]>( );
  1025. 							break;
  1026. 						case PrinterCategory.Physical:
  1027. 							_printercategory = PrinterCategory.Physical;
  1028. 							printerslist = allprinters.Where( p => p[8] == "1" ).ToList<System.String[]>( );
  1029. 							break;
  1030. 						case PrinterCategory.Virtual:
  1031. 							_printercategory = PrinterCategory.Virtual;
  1032. 							printerslist = allprinters.Where( p => p[8] == "0" ).ToList<System.String[]>( );
  1033. 							break;
  1034. 						default:
  1035. 							_debuginfo.Add( timestamp + "Printer category not recognized, assuming All" );
  1036. 							_errors.Add( Global.Common.TimeStamp( ) + "Printer category not recognized, assuming All" );
  1037. 							_printercategory = PrinterCategory.All;
  1038. 							printerslist = allprinters;
  1039. 							break;
  1040. 					}
  1041. 					_debuginfo.Add( timestamp + "Printer category: " + _printercategory.ToString( ) );
  1042. 					_debuginfo.Add( timestamp + "Number of printers in category " + printercategory + ": " + printerslist.Count );
  1043. 				}
  1044. 				else
  1045. 				{
  1046. 					_debuginfo.Add( timestamp + "Invalid printer category, assuming All" );
  1047. 					_errors.Add( Global.Common.TimeStamp( ) + "Invalid printer category, assuming All" );
  1048. 					_printercategory = PrinterCategory.All;
  1049. 					printerslist = allprinters;
  1050. 				}
  1051. 				if ( printerslist.Count == 0 )
  1052. 				{
  1053. 					_debuginfo.Add( timestamp + "No matching printers found in category " + _printercategory.ToString( ) );
  1054. 					_errors.Add( Global.Common.TimeStamp( ) + "No matching printers found in category " + _printercategory.ToString( ) );
  1055. 				}
  1056. 			}
  1057. 		}
  1058.  
  1059.  
  1060. 		private static string _selectedprinter = string.Empty;
  1061. 		[System.Runtime.InteropServices.ComVisible( true )]
  1062. 		public string selectedprinter
  1063. 		{
  1064. 			get
  1065. 			{
  1066. 				return _selectedprinter;
  1067. 			}
  1068. 		}
  1069.  
  1070.  
  1071. 		private int _timeout = defaulttimeout;
  1072. 		[System.Runtime.InteropServices.ComVisible( true )]
  1073. 		public int timeout
  1074. 		{
  1075. 			get
  1076. 			{
  1077. 				return _timeout;
  1078. 			}
  1079. 			set
  1080. 			{
  1081. 				if ( value < 0 || value > 3600 )
  1082. 				{
  1083. 					_timeout = 0;
  1084. 				}
  1085. 				else
  1086. 				{
  1087. 					_timeout = value;
  1088. 				}
  1089. 			}
  1090. 		}
  1091.  
  1092.  
  1093. 		private bool _timeoutelapsed = false;
  1094. 		[System.Runtime.InteropServices.ComVisible( true )]
  1095. 		public int timeoutelapsed
  1096. 		{
  1097. 			get
  1098. 			{
  1099. 				return ( _timeoutelapsed ? 1 : 0 );
  1100. 			}
  1101. 		}
  1102.  
  1103.  
  1104. 		public static string timestamp => Global.Common.TimeStamp( );
  1105.  
  1106.  
  1107. 		private string _title = defaulttitle;
  1108. 		[System.Runtime.InteropServices.ComVisible( true )]
  1109. 		public string title
  1110. 		{
  1111. 			get
  1112. 			{
  1113. 				return _title;
  1114. 			}
  1115. 			set
  1116. 			{
  1117. 				if ( string.IsNullOrWhiteSpace( value ) )
  1118. 				{
  1119. 					_title = string.Format( "{0},  Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion );
  1120. 				}
  1121. 				else
  1122. 				{
  1123. 					_title = value.Trim( );
  1124. 				}
  1125. 			}
  1126. 		}
  1127.  
  1128.  
  1129. 		private int _top = -1;
  1130. 		[System.Runtime.InteropServices.ComVisible( true )]
  1131. 		public int top
  1132. 		{
  1133. 			get
  1134. 			{
  1135. 				return _top;
  1136. 			}
  1137. 			set
  1138. 			{
  1139. 				if ( value < -1 )
  1140. 				{
  1141. 					_top = 0;
  1142. 				}
  1143. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight )
  1144. 				{
  1145. 					_top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight;
  1146. 				}
  1147. 				else
  1148. 				{
  1149. 					_top = value;
  1150. 				}
  1151. 			}
  1152. 		}
  1153.  
  1154.  
  1155. 		[System.Runtime.InteropServices.ComVisible( true )]
  1156. 		public string Version
  1157. 		{
  1158. 			get
  1159. 			{
  1160. 				return Global.Common.ProgramInfo.FileVersion;
  1161. 			}
  1162. 		}
  1163.  
  1164.  
  1165. 		private int _windowheight = defaultwindowheight;
  1166. 		[System.Runtime.InteropServices.ComVisible( true )]
  1167. 		public int windowheight
  1168. 		{
  1169. 			get
  1170. 			{
  1171. 				return _windowheight;
  1172. 			}
  1173. 			set
  1174. 			{
  1175. 				if ( value < defaultwindowheight )
  1176. 				{
  1177. 					_windowheight = defaultwindowheight;
  1178. 				}
  1179. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height )
  1180. 				{
  1181. 					_windowheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
  1182. 				}
  1183. 				else
  1184. 				{
  1185. 					_windowheight = value;
  1186. 				}
  1187. 			}
  1188. 		}
  1189.  
  1190.  
  1191. 		private int _windowwidth = defaultwindowwidth;
  1192. 		[System.Runtime.InteropServices.ComVisible( true )]
  1193. 		public int windowwidth
  1194. 		{
  1195. 			get
  1196. 			{
  1197. 				return _windowwidth;
  1198. 			}
  1199. 			set
  1200. 			{
  1201. 				if ( value < defaultwindowwidth )
  1202. 				{
  1203. 					_windowwidth = defaultwindowwidth;
  1204. 				}
  1205. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width )
  1206. 				{
  1207. 					_windowwidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
  1208. 				}
  1209. 				else
  1210. 				{
  1211. 					_windowwidth = value;
  1212. 				}
  1213. 			}
  1214. 		}
  1215.  
  1216. 		#endregion Properties
  1217.  
  1218.  
  1219. 		#region Event Handlers
  1220.  
  1221. 		private void PrinterSelectBox_Combobox_SelectedIndexChanged( object sender, System.EventArgs e )
  1222. 		{
  1223. 			_selectedprinter = printersdropdown.Text;
  1224. 			UpdatePrinterSelectBoxFields( );
  1225. 		}
  1226.  
  1227.  
  1228. 		private void PrinterSelectBox_Timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e )
  1229. 		{
  1230. 			_timeoutelapsed = true;
  1231. 			_selectedprinter = printersdropdown.Text;
  1232. 			printerselectform.Close( );
  1233. 		}
  1234.  
  1235. 		#endregion Event Handlers
  1236. 	}
  1237. }

page last modified: 2024-04-16; loaded in 0.0268 seconds