using System.Linq; namespace RobvanderWoude { [System.Runtime.InteropServices.Guid( "A201493F-EB79-4928-98A0-CA1BA5BF3B6B" )] public interface DropDownBox_Interface { [System.Runtime.InteropServices.DispId( 1 )] void CheckUpdate( ); [System.Runtime.InteropServices.DispId( 2 )] string Credits( ); [System.Runtime.InteropServices.DispId( 3 )] string Help( int html = 0 ); [System.Runtime.InteropServices.DispId( 4 )] string ListProperties( ); [System.Runtime.InteropServices.DispId( 5 )] string SampleCode( ); [System.Runtime.InteropServices.DispId( 6 )] void Show( ); } [System.Runtime.InteropServices.Guid( "BD2C3B92-F797-4D5B-B809-D64B13CD27CF" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )] public interface DropDownBox_Events { } [System.Runtime.InteropServices.Guid( "72B657DB-DEE3-45D4-9907-354CCBE01D7D" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( DropDownBox_Events ) )] public class DropDownBox : DropDownBox_Interface { #region Default Values const string defaultcaptioncancel = "Cancel"; const string defaultcaptionok = "OK"; static readonly System.Drawing.FontFamily defaultfontfamily = System.Drawing.FontFamily.GenericSansSerif; const float defaultfontsize = 10; static readonly string defaulttitle = string.Format( "{0}, Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion ); const int defaultwindowheight = 90; const int defaultwindowwidth = 200; const float minimumfontsize = 6; const float maximumfontsize = 48; #endregion Default Values static System.Collections.Generic.List dropdownlist = new System.Collections.Generic.List( ); static System.Timers.Timer timer; static System.Windows.Forms.Form dropdownboxform; static System.Windows.Forms.ComboBox combobox; #region Methods public void CheckUpdate( ) { Global.Common.ProgramInfo.CheckUpdate( ); } public string Credits( ) { return Global.Common.Credits( ); } public string Help( int html = 0 ) { int col1width = 0; int col2width = 0; int col3width = 0; int col4width = 0; int col5width = 0; string help = string.Empty; string linetemplate = string.Empty; string separatorline = string.Empty; if ( html == 1 ) { help += "

Help for DropDownBox class

\n\n"; help += "

Present a dropdown list of choices, and return the selected value

\n\n"; help += "

COM ProgID: RobvanderWoude.DropDownBox

\n\n"; } else { help += "Help for DropDownBox class\n"; help += new string( '\u2500', help.Length ) + "\n\n"; help += "Present a dropdown list of choices, and return the selected value\n\n\n"; help += "COM ProgID: RobvanderWoude.DropDownBox\n\n\n"; } #region Properties if ( html == 1) { separatorline = string.Empty; linetemplate = "\n\t{0}\n\t{1}\n\t{2}\n\t{3}\n\t{4}\n\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\n"; } else { col1width = 16; col2width = 50; col3width = 9; col4width = 9; col5width = 44; 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"; linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502 {3,-" + col4width.ToString( ) + "} \u2502 {4,-" + col5width.ToString( ) + "} \u2502\n"; help += "\u250C" + new string( '\u2500', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2510\n"; help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n"; 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)" ); help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n"; 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"; help += string.Format( linetemplate, "Property Name", "Description", "Mandatory", "Read-Only", "Default (Allowed) Values" ); 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"; } help += HelpTableRow( linetemplate, "captioncancel", Global.Common.Help.captioncancel, "no", "no", defaultcaptioncancel, html ); help += separatorline; help += HelpTableRow( linetemplate, "captionok", Global.Common.Help.captionok, "no", "no", defaultcaptionok, html ); help += separatorline; help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "defaultindex", "Index of initially selected item in dropdown", "no", "no", "-1: none selected", html ); help += separatorline; help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "fontfamily", Global.Common.Help.fontfamily, "no", "no", defaultfontfamily.Name, html ); help += separatorline; help += HelpTableRow( linetemplate, "fontsize", Global.Common.Help.fontsize, "no", "no", string.Format( "{0} ({1}..{2})", defaultfontsize, minimumfontsize, maximumfontsize ), html ); help += separatorline; help += HelpTableRow( linetemplate, "left", Global.Common.Help.left, "no", "no", "Centered (0..screenwidth-windowwidth)", html ); help += separatorline; if ( html == 1 ) { string template = "\n\t\n\t\n\t\n\t\n\t\n\n"; help += string.Format( template, "list", "Semicolon-separated list of items for dropdown", "* YES", "no", "* Set either \"list\" or \"listfile\" property" ); template = "\n\t\n\t\n\t\n\n"; help += string.Format( template, "listfile", "Path to file containing list", "no" ); } else { help += HelpTableRow( linetemplate, "list", "Semicolon-separated list of items for dropdown", "", "no", "", html ); help += "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u2524 " + string.Format( "{0,-" + col3width + "}", "* YES" ) + " \u251C" + new string( '\u2500', 2 + col4width ) + "\u2524 " + string.Format( "{0,-" + col5width + "}", "* Set either \"list\" or \"listfile\" property" ) + " \u2502\n"; help += HelpTableRow( linetemplate, "listfile", "Path to file containing list", "", "no", new string( ' ', 6 ) + new string( '\u2550', 6 ) + new string( ' ', 8 ) + new string( '\u2550', 2 ), html ); } help += separatorline; help += HelpTableRow( linetemplate, "literal", Global.Common.Help.literal, "no", "no", "0: interpret \"\\t\" as tab and \"\\n\" as newline", html ); help += separatorline; help += HelpTableRow( linetemplate, "localizecaptions", Global.Common.Help.localizecaptions, "no", "no", "0: English captions", html ); help += separatorline; help += HelpTableRow( linetemplate, "modal", Global.Common.Help.modal, "no", "no", "1: always on top", html ); help += separatorline; help += HelpTableRow( linetemplate, "prompt", Global.Common.Help.prompt, "no", "no", "No prompt", html ); help += separatorline; help += HelpTableRow( linetemplate, "selectedindex", "Index of last selected dropdown item", "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "selecteditem", "Text of last selected dropdown item", "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "timeout", Global.Common.Help.timeout, "no", "no", "0: no timeout", html ); help += separatorline; help += HelpTableRow( linetemplate, "timeoutelapsed", Global.Common.Help.timeoutelapsed, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "title", Global.Common.Help.title, "no", "no", defaulttitle, html ); help += separatorline; help += HelpTableRow( linetemplate, "top", Global.Common.Help.top, "no", "no", "Centered (0..screenheight-windowheight)", html ); help += separatorline; help += HelpTableRow( linetemplate, "Version", Global.Common.Help.version, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "windowheight", "Height of dialog window", "no", "no", string.Format( "{0} ({0}..screenheight)", defaultwindowheight ), html ); help += separatorline; help += HelpTableRow( linetemplate, "windowwidth", "Width of dialog window", "no", "no", string.Format( "{0} ({0}..screenwidth)", defaultwindowwidth ), html ); if ( html == 1 ) { help += "
Properties (Note that all properties are string or integer, no booleans, objects or arrays)
Property NameDescriptionMandatoryRead-OnlyDefault (Allowed) Values
{0}{1}{2}{3}{4}
{0}{1}{2}
\n\n\n"; } else { 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"; } #endregion Properties #region Methods if ( html == 1 ) { separatorline = string.Empty; linetemplate = "\n\t{0}\n\t{1}\n\t{2}\n\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\n"; help += "\n"; help += "\t\n"; help += "\t\n"; help += "\t\n"; help += "\n"; } else { col1width = 16; col2width = 74; col3width = 44; separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u2524\n"; linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502\n"; help += "\u250C" + new string( '\u2500', 8 + col1width + col2width + col3width ) + "\u2510\n"; help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n"; help += string.Format( "\u2502 {0,-" + ( 6 + col1width + col2width + col3width ).ToString( ) + "} \u2502\n", "Methods" ); help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n"; help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2561\n"; help += string.Format( linetemplate, "Method Name", "Description", "Requirements" ); help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u2561\n"; } help += HelpTableRow( linetemplate, "CheckUpdate", Global.Common.Help._checkupdate, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "Credits", Global.Common.Help._credits, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "Help", Global.Common.Help._help, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "ListProperties", Global.Common.Help._listproperties, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "SampleCode", Global.Common.Help._samplecode, "", html ); help += separatorline; help += HelpTableRow( linetemplate, "Show", "Presents a dropdown dialog box based on the current property values, and if \"OK\" is clicked, saves the last selected item's index in \"selectedindex\" property, and its text value in \"selecteditem\" property (if \"Cancel\" is clicked, \"selectedindex\" is set to -1 and \"selecteditem\" to an empty string).", "Either \"list\" or \"listfile\" property must be set", html ); if ( html == 1 ) { help += "
Methods
Method NameDescriptionRequirements
\n\n\n"; } else { help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2518\n\n\n"; } #endregion Methods #region Example if ( html == 1 ) { help += "

VBScript usage example:

\n\n
";
			}
			else
			{
				help += "VBScript usage example:\n";
				help += new string( '\u2500', 23 ) + "\n\n";
			}

			help += SampleCode( );

			if ( html == 1 )
			{
				help += "
"; } help += "\n\n"; #endregion Example help = help.Replace( "\n", System.Environment.NewLine ); return help; } private string HelpTableRow( string template, string col1text, string col2text, string col3text, int html ) { if ( html == 1 ) { return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text ); } else { return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, "", "" ); } } private string HelpTableRow( string template, string col1text, string col2text, string col3text, string col4text, string col5text, int html ) { if ( html == 1 ) { return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text, col4text, col5text ); } else { return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, col4text, col5text ); } } public string ListProperties( ) { return Global.Common.Lists.Properties( this ); } public string SampleCode( ) { string code = "Set objDropDownBox = CreateObject( \"RobvanderWoude.DropDownBox\" )\n\n"; code += "With objDropDownBox\n"; code += "\t.list = \"Arizona;Texas;California;Washington;Montana;Utah\"\n"; code += "\t.defaultindex = 4\n"; code += "\t.prompt = \"You have 15 seconds to select a state\"\n"; code += "\t.top = 200\n"; code += "\t.left = 300\n"; code += "\t.timeout = 15\n"; code += "\t.Show\n"; code += "\tWScript.Echo \"Selected state: \" & .selecteditem\n"; code += "End With\n\n"; code += "Set objDropDownBox = Nothing"; return code; } [System.STAThread] public void Show( ) { if ( dropdownlist.Count == 0 ) { _errors.Add( Global.Common.TimeStamp( ) + "Show( ): No list specified" ); _selectedindex = -1; _selecteditem = string.Empty; } else { _selectedindex = defaultindex; #region Timer _timeoutelapsed = false; if ( _timeout > 0 ) { timer = new System.Timers.Timer( ); timer.Elapsed += new System.Timers.ElapsedEventHandler( DropDownBox_Class_Timer_Elapsed ); timer.Interval = timeout * 1000; timer.Start( ); } #endregion Timer #region Build Form dropdownboxform = new System.Windows.Forms.Form( ); System.Drawing.Size size = new System.Drawing.Size( windowwidth, windowheight ); dropdownboxform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; dropdownboxform.MaximizeBox = false; dropdownboxform.MinimizeBox = false; dropdownboxform.ClientSize = size; dropdownboxform.Text = title; dropdownboxform.TopMost = topmost; dropdownboxform.Font = new System.Drawing.Font( _fontfamily.Name, _fontsize ); if ( left == -1 || top == -1 ) { dropdownboxform.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; } else { dropdownboxform.StartPosition = System.Windows.Forms.FormStartPosition.Manual; dropdownboxform.Location = new System.Drawing.Point( left, top ); } _debuginfo.Add( timestamp + $"startposition = {dropdownboxform.StartPosition.ToString( )}; top = {top}; left = {left}; location = {dropdownboxform.Location.X},{dropdownboxform.Location.Y}" ); if ( !string.IsNullOrWhiteSpace( prompt ) ) { System.Windows.Forms.Label labelprompt = new System.Windows.Forms.Label( ); labelprompt.Size = new System.Drawing.Size( size.Width - 20, 20 ); labelprompt.Location = new System.Drawing.Point( 10, 10 ); labelprompt.Text = prompt.Replace( "\\n", "\n" ).Replace( "\\r", "\r" ); if ( windowheight == defaultwindowheight ) { // Add 20 to window height to allow space for prompt, IF and only IF the heigt wasn't set at a non-default value size = new System.Drawing.Size( size.Width, size.Height + 20 ); } dropdownboxform.ClientSize = size; labelprompt.Size = new System.Drawing.Size( size.Width - 20, size.Height - 90 ); dropdownboxform.Controls.Add( labelprompt ); } combobox = new System.Windows.Forms.ComboBox( ); combobox.Size = new System.Drawing.Size( size.Width - 20, 25 ); combobox.Location = new System.Drawing.Point( 10, size.Height - 70 ); combobox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append; combobox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; combobox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; combobox.SelectedIndexChanged += new System.EventHandler( DropDownBox_Class_ComboBox_SelectedIndexChanged ); dropdownboxform.Controls.Add( combobox ); System.Windows.Forms.Button okButton = new System.Windows.Forms.Button( ); okButton.DialogResult = System.Windows.Forms.DialogResult.OK; okButton.Name = "okButton"; okButton.Size = new System.Drawing.Size( 80, 25 ); okButton.Text = captionok; okButton.Location = new System.Drawing.Point( size.Width / 2 - 10 - 80, size.Height - 35 ); dropdownboxform.Controls.Add( okButton ); System.Windows.Forms.Button cancelButton = new System.Windows.Forms.Button( ); cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; cancelButton.Name = "cancelButton"; cancelButton.Size = new System.Drawing.Size( 80, 25 ); cancelButton.Text = captioncancel; cancelButton.Location = new System.Drawing.Point( size.Width / 2 + 10, size.Height - 35 ); dropdownboxform.Controls.Add( cancelButton ); dropdownboxform.AcceptButton = okButton; // OK on Enter dropdownboxform.CancelButton = cancelButton; // Cancel on Esc dropdownboxform.Activate( ); #endregion Build Form #region Populate Dropdown foreach ( string item in dropdownlist ) { combobox.Items.Add( item ); } // Preselect an item combobox.SelectedIndex = _defaultindex; #endregion Populate Dropdown _selectedindex = combobox.SelectedIndex; _selecteditem = combobox.Text; #region Show Dialog and Save Result System.Windows.Forms.DialogResult result = dropdownboxform.ShowDialog( ); if ( !_timeoutelapsed && result == System.Windows.Forms.DialogResult.Cancel ) { _selectedindex = -1; _selecteditem = string.Empty; } #endregion Show Dialog and Save Result } } #endregion Methods #region Properties private string _captioncancel = defaultcaptioncancel; [System.Runtime.InteropServices.ComVisible( true )] public string captioncancel { get { if ( _localizecaptions && _captioncancel == defaultcaptioncancel ) { _captioncancel = Global.Common.Localization.Load( "user32.dll", 801, defaultcaptioncancel ); } return _captioncancel; } set { if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 ) { _captioncancel = defaultcaptioncancel; } else { _captioncancel = value; } //_debuginfo.Add() } } private string _captionok = defaultcaptionok; [System.Runtime.InteropServices.ComVisible( true )] public string captionok { get { if ( _localizecaptions && _captionok == defaultcaptionok ) { _captionok = Global.Common.Localization.Load( "user32.dll", 800, defaultcaptionok ); } return _captionok; } set { if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 ) { _captionok = defaultcaptionok; } else { _captionok = value; } } } private System.Collections.Generic.List _debuginfo = new System.Collections.Generic.List( ); [System.Runtime.InteropServices.ComVisible( true )] public string debuginfo { get { return string.Join( "\n", _debuginfo.ToArray( ) ); } } private int _defaultindex = -1; [System.Runtime.InteropServices.ComVisible( true )] public int defaultindex { get { return _defaultindex; } set { if ( value < -1 ) { _debuginfo.Add( timestamp + "defaultindex < -1" ); _defaultindex = -1; } else if ( value >= dropdownlist.Count ) { _debuginfo.Add( timestamp + "dropdownlist.Count = " + dropdownlist.Count ); _defaultindex = -1; } else { _defaultindex = value; } _debuginfo.Add( timestamp + "defaultindex = " + value ); _selectedindex = _defaultindex; } } private System.Collections.Generic.List _errors = new System.Collections.Generic.List( ); [System.Runtime.InteropServices.ComVisible( true )] public string errors { get { return string.Join( "\n", _errors.ToArray( ) ); } } private System.Drawing.FontFamily _fontfamily = defaultfontfamily; [System.Runtime.InteropServices.ComVisible( true )] public string fontfamily { get { return _fontfamily.Name; } set { _fontfamily = Global.Common.Validate.FontFamily( value, defaultfontfamily ); } } private float _fontsize = defaultfontsize; [System.Runtime.InteropServices.ComVisible( true )] public int fontsize { get { return System.Convert.ToInt32( _fontsize ); } set { _fontsize = System.Convert.ToSingle( value ).LimitToRange( minimumfontsize, maximumfontsize ); } } private int _left = -1; [System.Runtime.InteropServices.ComVisible( true )] public int left { get { return _left; } set { if ( value < 0 ) { _left = 0; } else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth ) { _left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth; } else { _left = value; } } } private string _list = string.Empty; [System.Runtime.InteropServices.ComVisible( true )] public string list { get { return _list; } set { _list = value; int errorcount = _errors.Count; string[] dropdownlistitems = null; if ( _list.IndexOf( ';' ) == -1 ) { _errors.Add( Global.Common.TimeStamp( ) + "Invalid list argument" ); } else { dropdownlistitems = _list.Split( ";".ToCharArray( ), System.StringSplitOptions.RemoveEmptyEntries ); } if ( errorcount == _errors.Count ) { dropdownlist = dropdownlistitems.ToList( ); if ( defaultindex > dropdownlist.Count ) { defaultindex = -1; } } else { _list = string.Empty; dropdownlist.Clear( ); } } } private string _listfile = string.Empty; [System.Runtime.InteropServices.ComVisible( true )] public string listfile { get { return _listfile; } set { _listfile = value; int errorcount = _errors.Count; string[] dropdownlistitems = null; if ( System.IO.File.Exists( _list ) ) { try { System.IO.StreamReader sr = new System.IO.StreamReader( list ); string text = sr.ReadToEnd( ); sr.Close( ); if ( text.IndexOfAny( ";\n\r".ToCharArray( ) ) == -1 ) { _errors.Add( Global.Common.TimeStamp( ) + "Invalid list file content" ); } dropdownlistitems = text.Split( ";\n\r".ToCharArray( ), System.StringSplitOptions.RemoveEmptyEntries ); } catch ( System.Exception e ) { _errors.Add( Global.Common.TimeStamp( ) + "Unable to open list file: " + e.Message ); } } else { _errors.Add( Global.Common.TimeStamp( ) + "List file not found" ); } if ( errorcount == _errors.Count ) { dropdownlist = dropdownlistitems.ToList( ); if ( defaultindex > dropdownlist.Count ) { defaultindex = -1; } } else { _listfile = string.Empty; dropdownlist.Clear( ); } } } private bool _literal = false; [System.Runtime.InteropServices.ComVisible( true )] public int literal { get { return ( _literal ? 1 : 0 ); } set { _literal = ( value == 1 ); } } private bool _localizecaptions = false; [System.Runtime.InteropServices.ComVisible( true )] public int localizecaptions { get { return ( _localizecaptions ? 1 : 0 ); } set { _localizecaptions = ( value == 1 ); } } private bool topmost = true; [System.Runtime.InteropServices.ComVisible( true )] public int modal { get { return ( topmost ? 1 : 0 ); } set { topmost = ( value == 1 ); } } private string _prompt = string.Empty; [System.Runtime.InteropServices.ComVisible( true )] public string prompt { get { return _prompt; } set { if ( _literal ) { _prompt = value.Trim( ); } else { _prompt = value.Replace( "\\n", "\n" ).Replace( "\\t", "\t" ).Trim( ); } } } private int _selectedindex = -1; [System.Runtime.InteropServices.ComVisible( true )] public int selectedindex { get { return _selectedindex; } } private string _selecteditem = string.Empty; [System.Runtime.InteropServices.ComVisible( true )] public string selecteditem { get { return _selecteditem; } } private int _timeout = 0; [System.Runtime.InteropServices.ComVisible( true )] public int timeout { get { return _timeout; } set { if ( value < 0 || value > 3600 ) { _timeout = 0; } else { _timeout = value; } } } private bool _timeoutelapsed = false; [System.Runtime.InteropServices.ComVisible( true )] public int timeoutelapsed { get { return ( _timeoutelapsed ? 1 : 0 ); } } public static string timestamp => Global.Common.TimeStamp( ); private string _title = defaulttitle; [System.Runtime.InteropServices.ComVisible( true )] public string title { get { return _title; } set { if ( string.IsNullOrWhiteSpace( value ) ) { _title = defaulttitle; } else { _title = value.Trim( ); } } } private int _top = -1; [System.Runtime.InteropServices.ComVisible( true )] public int top { get { return _top; } set { if ( value < 0 ) { _top = 0; } else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight ) { _top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight; } else { _top = value; } } } [System.Runtime.InteropServices.ComVisible( true )] public string Version { get { return Global.Common.ProgramInfo.FileVersion; } } private int _windowheight = defaultwindowheight; [System.Runtime.InteropServices.ComVisible( true )] public int windowheight { get { return _windowheight; } set { if ( value < defaultwindowheight ) { _windowheight = defaultwindowheight; } else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height ) { _windowheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; } else { _windowheight = value; } } } private int _windowwidth = defaultwindowwidth; [System.Runtime.InteropServices.ComVisible( true )] public int windowwidth { get { return _windowwidth; } set { if ( value < defaultwindowwidth ) { _windowwidth = defaultwindowwidth; } else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width ) { _windowwidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; } else { _windowwidth = value; } } } #endregion Properties #region Event Handlers private void DropDownBox_Class_ComboBox_SelectedIndexChanged( object sender, System.EventArgs e ) { combobox.Update( ); _selectedindex = combobox.SelectedIndex; _selecteditem = combobox.Text; } private void DropDownBox_Class_Timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e ) { _timeoutelapsed = true; combobox.Update( ); _selectedindex = combobox.SelectedIndex; _selecteditem = combobox.Text; dropdownboxform.Close( ); } #endregion Event Handlers } }