Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dialogboxes_inputbox.cs

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

  1. using System.Linq;
  2.  
  3.  
  4. namespace RobvanderWoude
  5. {
  6. 	[System.Runtime.InteropServices.Guid( "C2173D12-E144-43AB-9764-0BA52FD7F926" )]
  7. 	public interface InputBox_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 ListProperties( );
  20.  
  21. 		[System.Runtime.InteropServices.DispId( 5 )]
  22. 		string MaskLanguageTable( );
  23.  
  24. 		[System.Runtime.InteropServices.DispId( 6 )]
  25. 		string SampleCode( );
  26.  
  27. 		[System.Runtime.InteropServices.DispId( 7 )]
  28. 		void Show( );
  29. 	}
  30.  
  31.  
  32. 	[System.Runtime.InteropServices.Guid( "5CCE42CF-C0A6-4819-B29E-F4A3806C1BFD" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )]
  33. 	public interface InputBox_Events
  34. 	{
  35. 	}
  36.  
  37.  
  38. 	[System.Runtime.InteropServices.Guid( "E6F8076F-5145-4CB2-9ACF-597A98B4F5A1" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( InputBox_Events ) )]
  39. 	public class InputBox : InputBox_Interface
  40. 	{
  41. 		#region Default values
  42.  
  43. 		const string defaultcaptioncancel = "Cancel";
  44. 		const string defaultcaptionok = "OK";
  45. 		const string defaultcaptionshowpassword = "Show password";
  46. 		static readonly System.Drawing.FontFamily defaultfontfamily = System.Drawing.FontFamily.GenericSansSerif;
  47. 		const int defaultfontsize = 10;
  48. 		const string defaultmask = "";
  49. 		const char defaultpasswordchar = '*';
  50. 		const string defaultprompt = "Prompt";
  51. 		const int defaulttimeout = 0;
  52. 		const string defaulttitle = "Title";
  53. 		const int defaultwindowheight = 110;
  54. 		const int defaultwindowwidth = 200;
  55. 		const float maximumfontsize = 48;
  56. 		const float minimumfontsize = 6;
  57.  
  58. 		#endregion Default values
  59.  
  60.  
  61. 		#region Controls
  62.  
  63. 		System.Windows.Forms.Form inputboxform;
  64. 		static System.Windows.Forms.TextBox textbox;
  65. 		static System.Windows.Forms.MaskedTextBox maskedtextbox;
  66. 		static System.Windows.Forms.CheckBox showpasswordcheckbox;
  67. 		System.Timers.Timer timer;
  68.  
  69. 		#endregion Controls
  70.  
  71.  
  72. 		static string previousinput = string.Empty;
  73.  
  74.  
  75. 		#region Methods
  76.  
  77. 		public void CheckUpdate( )
  78. 		{
  79. 			Global.Common.ProgramInfo.CheckUpdate( );
  80. 		}
  81.  
  82.  
  83. 		public string Credits( )
  84. 		{
  85. 			return Global.Common.Credits( );
  86. 		}
  87.  
  88.  
  89. 		public string Help( int html = 0 )
  90. 		{
  91. 			int col1width = 0;
  92. 			int col2width = 0;
  93. 			int col3width = 0;
  94. 			int col4width = 0;
  95. 			int col5width = 0;
  96. 			string help = string.Empty;
  97. 			string linetemplate = string.Empty;
  98. 			string separatorline = string.Empty;
  99.  
  100. 			if ( html == 1 )
  101. 			{
  102. 				help += "<h1>Help for InputBox class</h1>\n\n";
  103. 				help += "<p>Present a prompt for input dialog, and return the text entered</p>\n\n";
  104. 				help += "<h2>COM ProgID: RobvanderWoude.InputBox</h2>\n\n";
  105. 			}
  106. 			else
  107. 			{
  108. 				help += "Help for InputBox class\n";
  109. 				help += new string( '\u2500', help.Length ) + "\n\n";
  110. 				help += "Present a prompt for input dialog, and return the text entered\n\n\n";
  111. 				help += "COM ProgID: RobvanderWoude.InputBox\n\n\n";
  112. 			}
  113.  
  114.  
  115. 			#region Properties
  116.  
  117. 			if ( html == 1 )
  118. 			{
  119. 				separatorline = string.Empty;
  120. 				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";
  121.  
  122. 				help += "<table>\n";
  123. 				help += "<tr>\n";
  124. 				help += "\t<th colspan=\"5\">Properties (Note that all properties are string or integer, no booleans, objects or arrays)</th>\n";
  125. 				help += "</tr>\n";
  126.  
  127. 				help += "<tr>\n";
  128. 				help += "\t<th>Property Name</th>\n";
  129. 				help += "\t<th>Description</th>\n";
  130. 				help += "\t<th>Mandatory</th>\n";
  131. 				help += "\t<th>Read-Only</th>\n";
  132. 				help += "\t<th>Default (Allowed) Values</th>\n";
  133. 				help += "</tr>\n";
  134. 			}
  135. 			else
  136. 			{
  137. 				col1width = 20;
  138. 				col2width = 50;
  139. 				col3width = 9;
  140. 				col4width = 9;
  141. 				col5width = 40;
  142.  
  143. 				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";
  144. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502 {3,-" + col4width.ToString( ) + "} \u2502 {4,-" + col5width.ToString( ) + "} \u2502\n";
  145.  
  146. 				help += "\u250C" + new string( '\u2500', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2510\n";
  147. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  148. 				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)" );
  149. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  150. 				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";
  151. 				help += string.Format( linetemplate, "Property Name", "Description", "Mandatory", "Read-Only", "Default (Allowed) Values" );
  152. 				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";
  153. 			}
  154.  
  155. 			help += HelpTableRow( linetemplate, "allowshowpassword", "Add \"Show password\" checkbox     (0=false; 1=true)", "no", "no", "0: no checkbox", html );
  156. 			help += separatorline;
  157.  
  158. 			help += HelpTableRow( linetemplate, "asciionly", "Allow only ASCII characters      (0=false; 1=true)", "no", "no", "0: allow all", html );
  159. 			help += separatorline;
  160.  
  161. 			help += HelpTableRow( linetemplate, "captioncancel", Global.Common.Help.captioncancel, "no", "no", defaultcaptioncancel, html );
  162. 			help += separatorline;
  163.  
  164. 			help += HelpTableRow( linetemplate, "captionok", Global.Common.Help.captionok, "no", "no", defaultcaptionok, html );
  165. 			help += separatorline;
  166.  
  167. 			help += HelpTableRow( linetemplate, "captionshowpassword", "Text for \"Show password\" checkbox", "no", "no", defaultcaptionshowpassword, html );
  168. 			help += separatorline;
  169.  
  170. 			help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html );
  171. 			help += separatorline;
  172.  
  173. 			help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html );
  174. 			help += separatorline;
  175.  
  176. 			help += HelpTableRow( linetemplate, "fontfamily", Global.Common.Help.fontfamily, "no", "no", defaultfontfamily.Name, html );
  177. 			help += separatorline;
  178.  
  179. 			help += HelpTableRow( linetemplate, "fontsize", Global.Common.Help.fontsize, "no", "no", string.Format( "{0} ({1}..{2})", defaultfontsize, minimumfontsize, maximumfontsize ), html );
  180. 			help += separatorline;
  181.  
  182. 			help += HelpTableRow( linetemplate, "hidepassword", "Hide input, for password dialogs (0=false; 1=true)", "no", "no", "0: show input", html );
  183. 			help += separatorline;
  184.  
  185. 			help += HelpTableRow( linetemplate, "initialinput", "Initial input (e.g. expected value)", "no", "no", "", html );
  186. 			help += separatorline;
  187.  
  188. 			help += HelpTableRow( linetemplate, "input", "Input as typed in text field", "no", "no", "", html );
  189. 			help += separatorline;
  190.  
  191. 			help += HelpTableRow( linetemplate, "left", Global.Common.Help.left, "no", "no", "Centered (0..screenwidth-windowwidth)", html );
  192. 			help += separatorline;
  193.  
  194. 			help += HelpTableRow( linetemplate, "localizecaptions", Global.Common.Help.localizecaptions, "no", "no", "0: English captions", html );
  195. 			help += separatorline;
  196.  
  197. 			help += HelpTableRow( linetemplate, "mask", "Optional mask to apply to input", "no", "no", "", html );
  198. 			help += separatorline;
  199.  
  200. 			help += HelpTableRow( linetemplate, "maskedinput", "Masked input, i.e. including mask literals", "no", "no", "", html );
  201. 			help += separatorline;
  202.  
  203. 			help += HelpTableRow( linetemplate, "modal", Global.Common.Help.modal, "no", "no", "1: always on top", html );
  204. 			help += separatorline;
  205.  
  206. 			help += HelpTableRow( linetemplate, "passwordchar", "Character used to hide input", "no", "no", "*", html );
  207. 			help += separatorline;
  208.  
  209. 			help += HelpTableRow( linetemplate, "prompt", Global.Common.Help.prompt, "no", "no", defaultprompt, html );
  210. 			help += separatorline;
  211.  
  212. 			help += HelpTableRow( linetemplate, "regexcasesensitive", "Case sensitive regexes (0=false; 1=true)", "no", "no", "1: case sensitive", html );
  213. 			help += separatorline;
  214.  
  215. 			help += HelpTableRow( linetemplate, "regexendresult", "Regex pattern applied to submitted input", "no", "no", ".*", html );
  216. 			help += separatorline;
  217.  
  218. 			help += HelpTableRow( linetemplate, "regexonthefly", "Regex pattern applied at eacht change of input", "no", "no", ".*", html );
  219. 			help += separatorline;
  220.  
  221. 			help += HelpTableRow( linetemplate, "showpassword", "\"Show password\" checkbox status        (1=checked)", "no", "no", "0: not checked", html );
  222. 			help += separatorline;
  223.  
  224. 			help += HelpTableRow( linetemplate, "timeout", Global.Common.Help.timeout, "no", "no", defaulttimeout.ToString( ), html );
  225. 			help += separatorline;
  226.  
  227. 			help += HelpTableRow( linetemplate, "timeoutelapsed", Global.Common.Help.timeoutelapsed, "N/A", "YES", "", html );
  228. 			help += separatorline;
  229.  
  230. 			help += HelpTableRow( linetemplate, "title", Global.Common.Help.title, "no", "no", defaulttitle, html );
  231. 			help += separatorline;
  232.  
  233. 			help += HelpTableRow( linetemplate, "top", Global.Common.Help.top, "no", "no", "Centered (0..screenheight-windowheight)", html );
  234. 			help += separatorline;
  235.  
  236. 			help += HelpTableRow( linetemplate, "Version", Global.Common.Help.version, "N/A", "YES", "", html );
  237. 			help += separatorline;
  238.  
  239. 			help += HelpTableRow( linetemplate, "windowheight", Global.Common.Help.windowheight, "no", "no", string.Format( "{0} ({0}..screenheight)", defaultwindowheight ), html );
  240. 			help += separatorline;
  241.  
  242. 			help += HelpTableRow( linetemplate, "windowwidth", Global.Common.Help.windowwidth, "no", "no", string.Format( "{0} ({0}..screenwidth)", defaultwindowwidth ), html );
  243.  
  244. 			if ( html == 1 )
  245. 			{
  246. 				help += "</table>\n\n\n";
  247. 			}
  248. 			else
  249. 			{
  250. 				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";
  251. 			}
  252.  
  253. 			#endregion Properties
  254.  
  255.  
  256. 			#region Methods
  257.  
  258. 			if ( html == 1 )
  259. 			{
  260. 				separatorline = string.Empty;
  261. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n</tr>\n";
  262.  
  263. 				help += "<table>\n";
  264. 				help += "<tr>\n";
  265. 				help += "\t<th colspan=\"3\">Methods</th>\n";
  266. 				help += "</tr>\n";
  267.  
  268. 				help += "<tr>\n";
  269. 				help += "\t<th>Method Name</th>\n";
  270. 				help += "\t<th>Description</th>\n";
  271. 				help += "\t<th>Requirements</th>\n";
  272. 				help += "</tr>\n";
  273. 			}
  274. 			else
  275. 			{
  276. 				col1width = 18;
  277. 				col2width = 74;
  278. 				col3width = 42;
  279.  
  280. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u2524\n";
  281. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502\n";
  282.  
  283. 				help += "\u250C" + new string( '\u2500', 8 + col1width + col2width + col3width ) + "\u2510\n";
  284. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  285. 				help += string.Format( "\u2502 {0,-" + ( 6 + col1width + col2width + col3width ).ToString( ) + "} \u2502\n", "Methods" );
  286. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  287. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  288. 				help += string.Format( linetemplate, "Method Name", "Description", "Requirements" );
  289. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  290. 			}
  291.  
  292. 			help += HelpTableRow( linetemplate, "CheckUpdate", Global.Common.Help._checkupdate, "", html );
  293. 			help += separatorline;
  294.  
  295. 			help += HelpTableRow( linetemplate, "Credits", Global.Common.Help._credits, "", html );
  296. 			help += separatorline;
  297.  
  298. 			help += HelpTableRow( linetemplate, "Help", Global.Common.Help._help, "", html );
  299. 			help += separatorline;
  300.  
  301. 			help += HelpTableRow( linetemplate, "ListProperties", Global.Common.Help._listproperties, "", html );
  302. 			help += separatorline;
  303.  
  304. 			help += HelpTableRow( linetemplate, "MaskLanguageTable", "Returns a table with an overview of the MaskedTextBox's masking language", "", html );
  305. 			help += separatorline;
  306.  
  307. 			help += HelpTableRow( linetemplate, "SampleCode", Global.Common.Help._samplecode, "", html );
  308. 			help += separatorline;
  309.  
  310. 			help += HelpTableRow( linetemplate, "Show", "Presents a prompt for input dialog based on the current property values, and if \"OK\" is clicked, saves the entered input in the \"input\" property.\nIf \"mask\" is specified, a masked textbox will be used, and if the entered text complies to the mask, it will be saved unmasked (without the mask literals) in the \"input\" property and masked (including mask literals) in the \"maskedinput\" property.\nIf \"Cancel\" is clicked, or if the entered input does not comply to the mask or does not match the regular expressions, \"input\" and \"maskedinput\" will both be empty.", "", html );
  311.  
  312. 			if ( html == 1 )
  313. 			{
  314. 				help += "</table>\n\n\n";
  315. 			}
  316. 			else
  317. 			{
  318. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2518\n\n\n";
  319. 			}
  320.  
  321. 			#endregion Methods
  322.  
  323.  
  324. 			#region Example
  325.  
  326. 			if ( html == 1 )
  327. 			{
  328. 				help += "<h2>VBScript usage example:</h2>\n\n<pre>";
  329. 			}
  330. 			else
  331. 			{
  332. 				help += "VBScript usage example:\n";
  333. 				help += new string( '\u2500', 23 ) + "\n\n";
  334. 			}
  335.  
  336. 			help += SampleCode( );
  337.  
  338. 			if ( html == 1 )
  339. 			{
  340. 				help += "</pre>";
  341. 			}
  342.  
  343. 			help += "\n\n";
  344.  
  345. 			#endregion Example
  346.  
  347.  
  348. 			help = help.Replace( "\n", System.Environment.NewLine );
  349. 			return help;
  350. 		}
  351.  
  352.  
  353. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, int html )
  354. 		{
  355. 			if ( html == 1 )
  356. 			{
  357. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text );
  358. 			}
  359. 			else
  360. 			{
  361. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, "", "" );
  362. 			}
  363. 		}
  364.  
  365.  
  366. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, string col4text, string col5text, int html )
  367. 		{
  368. 			if ( html == 1 )
  369. 			{
  370. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text, col4text, col5text );
  371. 			}
  372. 			else
  373. 			{
  374. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, col4text, col5text );
  375. 			}
  376. 		}
  377.  
  378.  
  379. 		public string ListProperties( )
  380. 		{
  381. 			return Global.Common.Lists.Properties( this );
  382. 		}
  383.  
  384.  
  385. 		public string MaskLanguageTable( )
  386. 		{
  387. 			return Global.Common.Lists.MaskLanguageTable( );
  388. 		}
  389.  
  390.  
  391. 		public string SampleCode( )
  392. 		{
  393. 			string code = "Set objInputBox = CreateObject( \"RobvanderWoude.InputBox\" )\n\n";
  394. 			code += "With objInputBox\n";
  395. 			code += "\t.prompt = \"Enter a MAC address\"\n";
  396. 			code += "\t.title = \"MAC Address\"\n";
  397. 			code += "\t.initialinput = \"0022446688AACCEE\"\n";
  398. 			code += "\t.mask = \">CC\\:CC\\:CC\\:CC\\:CC\\:CC\\:CC\\:CC\"\n";
  399. 			code += "\t.regexendresult = \"[\\dA - F]{16}\"\n";
  400. 			code += "\t.regexonthefly = \"[\\dA-F]{0,16}\"\n";
  401. 			code += "\t.regexcasesensitive = 0\n";
  402. 			code += "\t.timeout = 120\n";
  403. 			code += "\t.Show\n";
  404. 			code += "\tWScript.Echo \"New MAC address: \" & .input & \" (\" & .maskedinput & \")\"\n";
  405. 			code += "\tWScript.Echo\n";
  406. 			code += "\tWScript.Echo .ListProperties( )\n";
  407. 			code += "End With\n\n";
  408. 			code += "Set objInputBox = Nothing";
  409. 			return code;
  410. 		}
  411.  
  412.  
  413. 		public void Show( )
  414. 		{
  415. 			#region Apply Settings
  416.  
  417. 			if ( _hidepassword )
  418. 			{
  419. 				_passwordchar = '*';
  420. 			}
  421. 			else
  422. 			{
  423. 				_passwordchar = '\0';
  424. 			}
  425.  
  426. 			System.Drawing.Size textboxsize = new System.Drawing.Size( windowwidth - 20, 25 );
  427.  
  428. 			if ( _showpassword )
  429. 			{
  430. 				textboxlocation = new System.Drawing.Point( 10, windowheight - 100 );
  431. 			}
  432. 			else
  433. 			{
  434. 				textboxlocation = new System.Drawing.Point( 10, windowheight - 75 );
  435. 			}
  436.  
  437. 			_input = initialinput;
  438.  
  439. 			#endregion Apply Settings
  440.  
  441.  
  442. 			#region Timer
  443.  
  444. 			try
  445. 			{
  446.  
  447. 				_timeoutelapsed = false;
  448. 				if ( timeout > 0 )
  449. 				{
  450. 					timer = new System.Timers.Timer( );
  451. 					timer.Elapsed += new System.Timers.ElapsedEventHandler( InputBox_Timer_Elapsed );
  452. 					timer.Interval = timeout * 1000;
  453. 					timer.Start( );
  454. 				}
  455. 			}
  456. 			catch ( System.Exception e )
  457. 			{
  458. 				_errors.Add( timestamp + "Error while trying to create dialog: " + e.Message );
  459. 			}
  460.  
  461. 			#endregion Timer
  462.  
  463.  
  464. 			#region Build Form
  465.  
  466. 			try
  467. 			{
  468. 				inputboxform = new System.Windows.Forms.Form( );
  469. 				inputboxform.ClientSize = new System.Drawing.Size( windowwidth, windowheight );
  470. 				inputboxform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  471. 				inputboxform.Font = new System.Drawing.Font( _fontfamily, _fontsize, System.Drawing.FontStyle.Regular );
  472. 				inputboxform.MaximizeBox = false;
  473. 				inputboxform.MinimizeBox = false;
  474. 				if ( left < 0 || top < 0 )
  475. 				{
  476. 					inputboxform.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  477. 				}
  478. 				else
  479. 				{
  480. 					inputboxform.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  481. 					inputboxform.Location = new System.Drawing.Point( left, top );
  482. 				}
  483. 				inputboxform.Text = title;
  484. 				inputboxform.TopMost = topmost;
  485.  
  486. 				System.Windows.Forms.Label labelprompt = new System.Windows.Forms.Label( );
  487. 				labelprompt.Size = new System.Drawing.Size( windowwidth - 20, windowheight - 90 );
  488. 				labelprompt.Location = new System.Drawing.Point( 10, 10 );
  489. 				labelprompt.Text = prompt.Replace( "\\n", "\n" );
  490. 				inputboxform.Controls.Add( labelprompt );
  491.  
  492. 				if ( ValidateMask( mask ) )
  493. 				{
  494. 					#region Add MaskedTextBox
  495.  
  496. 					_debuginfo.Add( timestamp + "Mask validated, adding MaskedTextBox to form" );
  497. 					maskedtextbox = new System.Windows.Forms.MaskedTextBox( );
  498. 					maskedtextbox.AsciiOnly = _asciionly;
  499. 					maskedtextbox.Location = textboxlocation;
  500. 					maskedtextbox.Mask = mask;
  501. 					maskedtextbox.PasswordChar = _passwordchar;
  502. 					maskedtextbox.Text = input;
  503. 					maskedtextbox.TextMaskFormat = System.Windows.Forms.MaskFormat.IncludeLiterals;
  504. 					_maskedinput = maskedtextbox.Text;
  505. 					maskedtextbox.Size = textboxsize;
  506. 					maskedtextbox.KeyUp += new System.Windows.Forms.KeyEventHandler( InputBox_MaskedTextbox_KeyUp );
  507. 					inputboxform.Controls.Add( maskedtextbox );
  508.  
  509. 					#endregion Add MaskedTextBox
  510. 				}
  511. 				else
  512. 				{
  513. 					#region Add TextBox
  514.  
  515. 					_debuginfo.Add( timestamp + "Mask not validated, adding TextBox to form" );
  516. 					textbox = new System.Windows.Forms.TextBox( );
  517. 					textbox.PasswordChar = _passwordchar;
  518. 					textbox.Size = textboxsize;
  519. 					textbox.Location = textboxlocation;
  520. 					if ( _hidepassword )
  521. 					{
  522. 						_debuginfo.Add( timestamp + "Hide password" );
  523. 						if ( _allowshowpassword )
  524. 						{
  525. 							_debuginfo.Add( timestamp + "Allow showing hidden password" );
  526. 							// Insert a checkbox with label "Show password" 25 px below the textbox
  527. 							showpasswordcheckbox = new System.Windows.Forms.CheckBox( );
  528. 							showpasswordcheckbox.Checked = _showpassword;
  529. 							showpasswordcheckbox.Location = new System.Drawing.Point( 11, textbox.Location.Y + 25 );
  530. 							showpasswordcheckbox.Width = inputboxform.Width - 22;
  531. 							showpasswordcheckbox.Click += new System.EventHandler( InputBox_ShowPasswordCheckbox_Click );
  532. 							showpasswordcheckbox.Text = captionshowpassword;
  533. 							inputboxform.Controls.Add( showpasswordcheckbox );
  534. 						}
  535. 					}
  536. 					else
  537. 					{
  538. 						textbox.Text = input;
  539. 					}
  540. 					textbox.KeyUp += new System.Windows.Forms.KeyEventHandler( InputBox_TextBox_KeyUp );
  541. 					inputboxform.Controls.Add( textbox );
  542.  
  543. 					#endregion Add TextBox
  544. 				}
  545.  
  546. 				#region Add Buttons
  547.  
  548. 				System.Windows.Forms.Button okButton = new System.Windows.Forms.Button( );
  549. 				okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  550. 				okButton.Name = "okButton";
  551. 				okButton.Size = new System.Drawing.Size( 80, 25 );
  552. 				okButton.Text = captionok;
  553. 				okButton.Location = new System.Drawing.Point( windowwidth / 2 - 10 - 80, windowheight - 40 );
  554. 				inputboxform.Controls.Add( okButton );
  555.  
  556. 				System.Windows.Forms.Button cancelButton = new System.Windows.Forms.Button( );
  557. 				cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  558. 				cancelButton.Name = "cancelButton";
  559. 				cancelButton.Size = new System.Drawing.Size( 80, 25 );
  560. 				cancelButton.Text = captioncancel;
  561. 				cancelButton.Location = new System.Drawing.Point( windowwidth / 2 + 10, windowheight - 40 );
  562. 				inputboxform.Controls.Add( cancelButton );
  563.  
  564. 				#endregion Add Buttons
  565.  
  566. 				inputboxform.AcceptButton = okButton;  // OK on Enter
  567. 				inputboxform.CancelButton = cancelButton; // Cancel on Esc
  568. 				inputboxform.Activate( );
  569. 				inputboxform.BringToFront( );
  570. 				inputboxform.Focus( );
  571.  
  572. 				if ( ValidateMask( mask ) )
  573. 				{
  574. 					maskedtextbox.BringToFront( ); // Bug workaround
  575. 					maskedtextbox.Select( 0, 0 ); // Move cursor to begin
  576. 					maskedtextbox.Focus( );
  577. 				}
  578. 				else
  579. 				{
  580. 					textbox.BringToFront( ); // Bug workaround
  581. 					textbox.Select( 0, 0 ); // Move cursor to begin
  582. 					textbox.Focus( );
  583. 				}
  584. 			}
  585. 			catch ( System.Exception e )
  586. 			{
  587. 				_errors.Add( timestamp + "Error while trying to create dialog: " + e.Message );
  588. 			}
  589.  
  590. 			#endregion Build Form
  591.  
  592.  
  593. 			#region Show Dialog and Return Result
  594.  
  595. 			try
  596. 			{
  597. 				System.Windows.Forms.DialogResult result = inputboxform.ShowDialog( );
  598. 				if ( !_timeoutelapsed && result == System.Windows.Forms.DialogResult.Cancel )
  599. 				{
  600. 					_input = string.Empty;
  601. 				}
  602. 			}
  603. 			catch ( System.Exception e )
  604. 			{
  605. 				_errors.Add( timestamp + "Error while trying to show dialog: " + e.Message );
  606. 			}
  607.  
  608. 			#endregion Show Dialog and Return Result
  609. 		}
  610.  
  611.  
  612. 		public static void ValidateAndSaveResult( )
  613. 		{
  614. 			// Read input from MaskedTextBox or TextBox
  615. 			if ( ValidateMask( _mask ) )
  616. 			{
  617. 				_debuginfo.Add( timestamp + "Mask validated" );
  618. 				_debuginfo.Add( timestamp + "Retrieving unmasked input" );
  619. 				maskedtextbox.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
  620. 				_input = maskedtextbox.Text;
  621. 				_debuginfo.Add( timestamp + "Unmasked input: " + _input );
  622. 				_debuginfo.Add( timestamp + "Retrieving masked input" );
  623. 				maskedtextbox.TextMaskFormat = System.Windows.Forms.MaskFormat.IncludeLiterals;
  624. 				_maskedinput = maskedtextbox.Text;
  625. 				_debuginfo.Add( timestamp + "Unmasked input: " + _maskedinput );
  626. 				// Check if input complies with mask
  627. 				if ( !maskedtextbox.MaskCompleted )
  628. 				{
  629. 					_errors.Add( timestamp + "Input did not comply with mask" );
  630. 					_input = string.Empty;
  631. 					_maskedinput = string.Empty;
  632. 				}
  633. 			}
  634. 			else
  635. 			{
  636. 				_input = textbox.Text;
  637. 				_maskedinput = _input;
  638. 			}
  639.  
  640. 			// Check if input complies with regex
  641. 			if ( !string.IsNullOrWhiteSpace( _regexendresult ) && !System.Text.RegularExpressions.Regex.IsMatch( _input, _regexendresult, _regexcasesensitivity ) )
  642. 			{
  643. 				_errors.Add( string.Format( "{0}Input \"{1}\" did not match regular expression \"{2}\"", timestamp, _input, _regexendresult ) );
  644. 				_input = string.Empty;
  645. 				_maskedinput = string.Empty;
  646. 			}
  647. 		}
  648.  
  649.  
  650. 		public static bool ValidateMask( string mask )
  651. 		{
  652. 			return ( mask.IndexOfAny( "09#L?&CAa.,:/&><|\\".ToCharArray( ) ) > -1 );
  653. 		}
  654.  
  655. 		#endregion Methods
  656.  
  657.  
  658. 		#region Properties
  659.  
  660. 		private bool _allowshowpassword = false;
  661. 		[System.Runtime.InteropServices.ComVisible( true )]
  662. 		public int allowshowpassword
  663. 		{
  664. 			get
  665. 			{
  666. 				return ( _allowshowpassword ? 1 : 0 );
  667. 			}
  668. 			set
  669. 			{
  670. 				_allowshowpassword = ( value == 1 );
  671. 			}
  672. 		}
  673.  
  674.  
  675. 		private bool _asciionly = false;
  676. 		[System.Runtime.InteropServices.ComVisible( true )]
  677. 		public int asciionly
  678. 		{
  679. 			get
  680. 			{
  681. 				return ( _asciionly ? 1 : 0 );
  682. 			}
  683. 			set
  684. 			{
  685. 				_asciionly = ( value == 1 );
  686. 			}
  687. 		}
  688.  
  689.  
  690. 		private string _captioncancel = defaultcaptioncancel;
  691. 		[System.Runtime.InteropServices.ComVisible( true )]
  692. 		public string captioncancel
  693. 		{
  694. 			get
  695. 			{
  696. 				if ( _localizecaptions && _captioncancel == defaultcaptioncancel )
  697. 				{
  698. 					_captioncancel = Global.Common.Localization.Load( "user32.dll", 801, defaultcaptioncancel );
  699. 				}
  700. 				return _captioncancel;
  701. 			}
  702. 			set
  703. 			{
  704. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 )
  705. 				{
  706. 					_debuginfo.Add( timestamp + "Caption for \"Cancel\" button set to default because the value is too long or empty" );
  707. 					_captioncancel = defaultcaptioncancel;
  708. 				}
  709. 				else
  710. 				{
  711. 					_captioncancel = value;
  712. 				}
  713. 				//_debuginfo.Add()
  714. 			}
  715. 		}
  716.  
  717.  
  718. 		private string _captionok = defaultcaptionok;
  719. 		[System.Runtime.InteropServices.ComVisible( true )]
  720. 		public string captionok
  721. 		{
  722. 			get
  723. 			{
  724. 				if ( _localizecaptions && _captionok == defaultcaptionok )
  725. 				{
  726. 					_captionok = Global.Common.Localization.Load( "user32.dll", 800, defaultcaptionok );
  727. 				}
  728. 				return _captionok;
  729. 			}
  730. 			set
  731. 			{
  732. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 )
  733. 				{
  734. 					_debuginfo.Add( timestamp + "Caption for \"OK\" button set to default because the value is too long or empty" );
  735. 					_captionok = defaultcaptionok;
  736. 				}
  737. 				else
  738. 				{
  739. 					_captionok = value.Trim( );
  740. 				}
  741. 			}
  742. 		}
  743.  
  744.  
  745. 		private string _captionshowpassword = defaultcaptionshowpassword;
  746. 		[System.Runtime.InteropServices.ComVisible( true )]
  747. 		public string captionshowpassword
  748. 		{
  749. 			get
  750. 			{
  751. 				return _captionshowpassword;
  752. 			}
  753. 			set
  754. 			{
  755. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 40 )
  756. 				{
  757. 					_debuginfo.Add( timestamp + "Caption for \"Show password\" set to default because the value is too long or empty" );
  758. 					_captionshowpassword = defaultcaptionshowpassword;
  759. 				}
  760. 				else
  761. 				{
  762. 					_captionshowpassword = value.Trim( );
  763. 				}
  764. 			}
  765. 		}
  766.  
  767.  
  768. 		private static System.Collections.Generic.List<string> _debuginfo = new System.Collections.Generic.List<string>( );
  769. 		[System.Runtime.InteropServices.ComVisible( true )]
  770. 		public string debuginfo
  771. 		{
  772. 			get
  773. 			{
  774. 				return string.Join( "\n", _debuginfo.ToArray( ) );
  775. 			}
  776. 		}
  777.  
  778.  
  779. 		private static System.Collections.Generic.List<string> _errors = new System.Collections.Generic.List<string>( );
  780. 		[System.Runtime.InteropServices.ComVisible( true )]
  781. 		public string errors
  782. 		{
  783. 			get
  784. 			{
  785. 				return string.Join( "\n", _errors.ToArray( ) );
  786. 			}
  787. 		}
  788.  
  789.  
  790. 		private System.Drawing.FontFamily _fontfamily = defaultfontfamily;
  791. 		[System.Runtime.InteropServices.ComVisible( true )]
  792. 		public string fontfamily
  793. 		{
  794. 			get
  795. 			{
  796. 				return _fontfamily.Name;
  797. 			}
  798. 			set
  799. 			{
  800. 				_fontfamily = Global.Common.Validate.FontFamily( value, defaultfontfamily );
  801. 			}
  802. 		}
  803.  
  804.  
  805. 		private float _fontsize = defaultfontsize;
  806. 		[System.Runtime.InteropServices.ComVisible( true )]
  807. 		public int fontsize
  808. 		{
  809. 			get
  810. 			{
  811. 				return System.Convert.ToInt32( _fontsize );
  812. 			}
  813. 			set
  814. 			{
  815. 				_fontsize = System.Convert.ToSingle( value ).LimitToRange( minimumfontsize, maximumfontsize );
  816. 			}
  817. 		}
  818.  
  819.  
  820. 		private bool _hidepassword = false;
  821. 		[System.Runtime.InteropServices.ComVisible( true )]
  822. 		public int hidepassword
  823. 		{
  824. 			get
  825. 			{
  826. 				return ( _hidepassword ? 1 : 0 );
  827. 			}
  828. 			set
  829. 			{
  830. 				_hidepassword = ( value == 1 );
  831. 			}
  832. 		}
  833.  
  834.  
  835. 		private string _initialinput = string.Empty;
  836. 		[System.Runtime.InteropServices.ComVisible( true )]
  837. 		public string initialinput
  838. 		{
  839. 			get
  840. 			{
  841. 				return _initialinput;
  842. 			}
  843. 			set
  844. 			{
  845. 				_initialinput = value;
  846. 			}
  847. 		}
  848.  
  849.  
  850. 		private static string _input = string.Empty;
  851. 		[System.Runtime.InteropServices.ComVisible( true )]
  852. 		public string input
  853. 		{
  854. 			get
  855. 			{
  856. 				return _input;
  857. 			}
  858. 		}
  859.  
  860.  
  861. 		private int _left = -1;
  862. 		[System.Runtime.InteropServices.ComVisible( true )]
  863. 		public int left
  864. 		{
  865. 			get
  866. 			{
  867. 				return _left;
  868. 			}
  869. 			set
  870. 			{
  871. 				if ( value < 0 )
  872. 				{
  873. 					_left = 0;
  874. 				}
  875. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth )
  876. 				{
  877. 					_left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth;
  878. 				}
  879. 				else
  880. 				{
  881. 					_left = value;
  882. 				}
  883. 			}
  884. 		}
  885.  
  886.  
  887. 		private bool _localizecaptions = false;
  888. 		[System.Runtime.InteropServices.ComVisible( true )]
  889. 		public int localizecaptions
  890. 		{
  891. 			get
  892. 			{
  893. 				return ( _localizecaptions ? 1 : 0 );
  894. 			}
  895. 			set
  896. 			{
  897. 				_localizecaptions = ( value == 1 );
  898. 			}
  899. 		}
  900.  
  901.  
  902. 		private static string _mask = string.Empty;
  903. 		[System.Runtime.InteropServices.ComVisible( true )]
  904. 		public string mask
  905. 		{
  906. 			get
  907. 			{
  908. 				return _mask;
  909. 			}
  910. 			set
  911. 			{
  912. 				if ( ValidateMask( value ) )
  913. 				{
  914. 					_mask = value;
  915. 				}
  916. 				else
  917. 				{
  918. 					_mask = string.Empty;
  919. 				}
  920. 			}
  921. 		}
  922.  
  923.  
  924. 		private static string _maskedinput = string.Empty;
  925. 		[System.Runtime.InteropServices.ComVisible( true )]
  926. 		public string maskedinput
  927. 		{
  928. 			get
  929. 			{
  930. 				return _maskedinput;
  931. 			}
  932. 		}
  933.  
  934.  
  935. 		private bool topmost = true;
  936. 		[System.Runtime.InteropServices.ComVisible( true )]
  937. 		public int modal
  938. 		{
  939. 			get
  940. 			{
  941. 				return ( topmost ? 1 : 0 );
  942. 			}
  943. 			set
  944. 			{
  945. 				topmost = ( value == 1 );
  946. 			}
  947. 		}
  948.  
  949.  
  950. 		private static char _passwordchar = defaultpasswordchar;
  951. 		[System.Runtime.InteropServices.ComVisible( true )]
  952. 		public string passwordchar
  953. 		{
  954. 			get
  955. 			{
  956. 				if ( _passwordchar == '\0' )
  957. 				{
  958. 					return string.Empty;
  959. 				}
  960. 				else
  961. 				{
  962. 					return System.Convert.ToString( _passwordchar );
  963. 				}
  964. 			}
  965. 			set
  966. 			{
  967. 				if ( string.IsNullOrEmpty( value ) )
  968. 				{
  969. 					_debuginfo.Add( timestamp + "Empty password character not supported, using default * instead" );
  970. 					_passwordchar = defaultpasswordchar;
  971. 				}
  972. 				else
  973. 				{
  974. 					_debuginfo.Add( timestamp + "New password character set: \"" + passwordchar + "\"" );
  975. 					_passwordchar = value[0];
  976. 				}
  977. 			}
  978. 		}
  979.  
  980.  
  981. 		private string _prompt = defaultprompt;
  982. 		[System.Runtime.InteropServices.ComVisible( true )]
  983. 		public string prompt
  984. 		{
  985. 			get
  986. 			{
  987. 				return _prompt;
  988. 			}
  989. 			set
  990. 			{
  991. 				_prompt = value.Trim( );
  992. 			}
  993. 		}
  994.  
  995.  
  996. 		private static System.Text.RegularExpressions.RegexOptions _regexcasesensitivity = System.Text.RegularExpressions.RegexOptions.None;
  997. 		[System.Runtime.InteropServices.ComVisible( true )]
  998. 		public int regexcasesensitive
  999. 		{
  1000. 			get
  1001. 			{
  1002. 				if ( _regexcasesensitivity == System.Text.RegularExpressions.RegexOptions.None )
  1003. 				{
  1004. 					return 0;
  1005. 				}
  1006. 				else
  1007. 				{
  1008. 					return 1;
  1009. 				}
  1010. 			}
  1011. 			set
  1012. 			{
  1013. 				if ( value == 1 )
  1014. 				{
  1015. 					_regexcasesensitivity = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
  1016. 				}
  1017. 				else
  1018. 				{
  1019. 					_regexcasesensitivity = System.Text.RegularExpressions.RegexOptions.None;
  1020. 				}
  1021. 			}
  1022. 		}
  1023.  
  1024.  
  1025. 		private static string _regexendresult = ".*";
  1026. 		[System.Runtime.InteropServices.ComVisible( true )]
  1027. 		public string regexendresult
  1028. 		{
  1029. 			get
  1030. 			{
  1031. 				return _regexendresult;
  1032. 			}
  1033. 			set
  1034. 			{
  1035. 				if ( Global.Common.TestIfRegexPattern( value ) )
  1036. 				{
  1037. 					_regexendresult = value;
  1038. 				}
  1039. 			}
  1040. 		}
  1041.  
  1042.  
  1043. 		private static string _regexonthefly = ".*";
  1044. 		[System.Runtime.InteropServices.ComVisible( true )]
  1045. 		public string regexonthefly
  1046. 		{
  1047. 			get
  1048. 			{
  1049. 				return _regexonthefly;
  1050. 			}
  1051. 			set
  1052. 			{
  1053. 				if ( Global.Common.TestIfRegexPattern( value ) )
  1054. 				{
  1055. 					_regexonthefly = value;
  1056. 				}
  1057. 			}
  1058. 		}
  1059.  
  1060.  
  1061. 		private bool _showpassword = false;
  1062. 		[System.Runtime.InteropServices.ComVisible( true )]
  1063. 		public int showpassword
  1064. 		{
  1065. 			get
  1066. 			{
  1067. 				return ( _showpassword ? 1 : 0 );
  1068. 			}
  1069. 			set
  1070. 			{
  1071. 				_showpassword = ( value == 1 );
  1072. 			}
  1073. 		}
  1074.  
  1075.  
  1076. 		private System.Drawing.Point textboxlocation { get; set; }
  1077.  
  1078.  
  1079. 		private int _timeout = 0;
  1080. 		[System.Runtime.InteropServices.ComVisible( true )]
  1081. 		public int timeout
  1082. 		{
  1083. 			get
  1084. 			{
  1085. 				return _timeout;
  1086. 			}
  1087. 			set
  1088. 			{
  1089. 				if ( value < 0 || value > 3600 )
  1090. 				{
  1091. 					_timeout = 0;
  1092. 				}
  1093. 				else
  1094. 				{
  1095. 					_timeout = value;
  1096. 				}
  1097. 			}
  1098. 		}
  1099.  
  1100.  
  1101. 		private bool _timeoutelapsed = false;
  1102. 		[System.Runtime.InteropServices.ComVisible( true )]
  1103. 		public int timeoutelapsed
  1104. 		{
  1105. 			get
  1106. 			{
  1107. 				return ( _timeoutelapsed ? 1 : 0 );
  1108. 			}
  1109. 		}
  1110.  
  1111.  
  1112. 		private static string timestamp => Global.Common.TimeStamp( );
  1113.  
  1114.  
  1115. 		private string _title = defaulttitle;
  1116. 		[System.Runtime.InteropServices.ComVisible( true )]
  1117. 		public string title
  1118. 		{
  1119. 			get
  1120. 			{
  1121. 				return _title;
  1122. 			}
  1123. 			set
  1124. 			{
  1125. 				if ( string.IsNullOrWhiteSpace( value ) )
  1126. 				{
  1127. 					_title = defaulttitle;
  1128. 				}
  1129. 				else
  1130. 				{
  1131. 					_title = value.Trim( );
  1132. 				}
  1133. 			}
  1134. 		}
  1135.  
  1136.  
  1137. 		private int _top = -1;
  1138. 		[System.Runtime.InteropServices.ComVisible( true )]
  1139. 		public int top
  1140. 		{
  1141. 			get
  1142. 			{
  1143. 				return _top;
  1144. 			}
  1145. 			set
  1146. 			{
  1147. 				if ( value < 0 )
  1148. 				{
  1149. 					_top = 0;
  1150. 				}
  1151. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight )
  1152. 				{
  1153. 					_top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight;
  1154. 				}
  1155. 				else
  1156. 				{
  1157. 					_top = value;
  1158. 				}
  1159. 			}
  1160. 		}
  1161.  
  1162.  
  1163. 		[System.Runtime.InteropServices.ComVisible( true )]
  1164. 		public string Version
  1165. 		{
  1166. 			get
  1167. 			{
  1168. 				return Global.Common.ProgramInfo.FileVersion;
  1169. 			}
  1170. 		}
  1171.  
  1172.  
  1173. 		private static int _windowheight = defaultwindowheight;
  1174. 		[System.Runtime.InteropServices.ComVisible( true )]
  1175. 		public int windowheight
  1176. 		{
  1177. 			get
  1178. 			{
  1179. 				return _windowheight;
  1180. 			}
  1181. 			set
  1182. 			{
  1183. 				if ( value < defaultwindowheight )
  1184. 				{
  1185. 					_windowheight = defaultwindowheight;
  1186. 				}
  1187. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height )
  1188. 				{
  1189. 					_windowheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
  1190. 				}
  1191. 				else
  1192. 				{
  1193. 					_windowheight = value;
  1194. 				}
  1195. 			}
  1196. 		}
  1197.  
  1198.  
  1199. 		private static int _windowwidth = defaultwindowwidth;
  1200. 		[System.Runtime.InteropServices.ComVisible( true )]
  1201. 		public int windowwidth
  1202. 		{
  1203. 			get
  1204. 			{
  1205. 				return _windowwidth;
  1206. 			}
  1207. 			set
  1208. 			{
  1209. 				if ( value < defaultwindowwidth )
  1210. 				{
  1211. 					_windowwidth = defaultwindowwidth;
  1212. 				}
  1213. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width )
  1214. 				{
  1215. 					_windowwidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
  1216. 				}
  1217. 				else
  1218. 				{
  1219. 					_windowwidth = value;
  1220. 				}
  1221. 			}
  1222. 		}
  1223.  
  1224. 		#endregion Properties
  1225.  
  1226.  
  1227. 		#region Event Handlers
  1228.  
  1229. 		private void InputBox_Timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e )
  1230. 		{
  1231. 			_timeoutelapsed = true;
  1232. 			ValidateAndSaveResult( );
  1233. 			inputboxform.Close( );
  1234. 		}
  1235.  
  1236.  
  1237. 		private void InputBox_TextBox_KeyUp( object sender, System.Windows.Forms.KeyEventArgs e )
  1238. 		{
  1239. 			_input = textbox.Text;
  1240. 			if ( System.Text.RegularExpressions.Regex.IsMatch( input, regexonthefly, _regexcasesensitivity ) )
  1241. 			{
  1242. 				previousinput = input;
  1243. 			}
  1244. 			else
  1245. 			{
  1246. 				_input = previousinput;
  1247. 			}
  1248. 			if ( textbox.Text != input )
  1249. 			{
  1250. 				textbox.Text = input;
  1251. 				textbox.SelectionStart = input.Length;
  1252. 			}
  1253. 		}
  1254.  
  1255.  
  1256. 		private void InputBox_MaskedTextbox_KeyUp( object sender, System.Windows.Forms.KeyEventArgs e )
  1257. 		{
  1258. 			maskedtextbox.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
  1259. 			_input = maskedtextbox.Text;
  1260. 			if ( System.Text.RegularExpressions.Regex.IsMatch( input, regexonthefly, _regexcasesensitivity ) )
  1261. 			{
  1262. 				previousinput = input;
  1263. 			}
  1264. 			else
  1265. 			{
  1266. 				_input = previousinput;
  1267. 			}
  1268. 			if ( maskedtextbox.Text != input )
  1269. 			{
  1270. 				maskedtextbox.Text = input;
  1271. 				if ( input.Length > 0 )
  1272. 				{
  1273. 					maskedtextbox.SelectionStart = maskedtextbox.Text.LastIndexOf( input.Last<char>( ) ) + 1;
  1274. 				}
  1275. 				else
  1276. 				{
  1277. 					maskedtextbox.SelectionStart = 0;
  1278. 				}
  1279. 			}
  1280. 			maskedtextbox.TextMaskFormat = System.Windows.Forms.MaskFormat.IncludeLiterals;
  1281. 			_maskedinput = maskedtextbox.Text;
  1282. 			maskedtextbox.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
  1283. 		}
  1284.  
  1285.  
  1286. 		private void InputBox_ShowPasswordCheckbox_Click( object sender, System.EventArgs e )
  1287. 		{
  1288. 			// Toggle between hidden and normal text
  1289. 			if ( _passwordchar == '*' )
  1290. 			{
  1291. 				_passwordchar = '\0';
  1292. 			}
  1293. 			else
  1294. 			{
  1295. 				_passwordchar = '*';
  1296. 			}
  1297.  
  1298. 			if ( ValidateMask( mask ) )
  1299. 			{
  1300. 				maskedtextbox.PasswordChar = _passwordchar;
  1301.  
  1302. 			}
  1303. 			else
  1304. 			{
  1305. 				textbox.PasswordChar = _passwordchar;
  1306. 			}
  1307. 		}
  1308.  
  1309. 		#endregion Event Handlers
  1310. 	}
  1311. }
  1312.  

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