using System.Linq; namespace RobvanderWoude { [System.Runtime.InteropServices.Guid( "D2721C87-05FE-4D16-89A1-B3AE2E1AF30A" )] public interface DialogBoxes_Interface { [System.Runtime.InteropServices.DispId( 1 )] string AllColorsSelectBox( int allowcustomcolors = 1 ); [System.Runtime.InteropServices.DispId( 2 )] void CheckUpdate( ); [System.Runtime.InteropServices.DispId( 3 )] string ConsoleColorSelectBox( string title = "", int timeout = 0, int left = -1, int top = -1 ); [System.Runtime.InteropServices.DispId( 4 )] string Credits( ); [System.Runtime.InteropServices.DispId( 5 )] string DateTimeBox( string title = "", string initialdt = "", string culture = "fr-CA", string dateformat = "yyyy-MM-dd", string timeformat = "HH:mm:ss", int dateonly = 0, int timeonly = 0, string earliestdate = "", string latestdate = "", int minimumoffset = 0, int maximumoffset = 0, int windowwidth = 0, int windowheight = 0, string okcaption = "OK", string cancelcaption = "Cancel" ); [System.Runtime.InteropServices.DispId( 6 )] string DropDownBox( string list, string prompt = "", string title = "", int defaultindex = -1, int modal = 1, int windowwidth = 200, int windowheight = 90, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ); [System.Runtime.InteropServices.DispId( 7 )] string FontSelectBox( string fontname = "Courier New", int fontsize = 12, int minimumfontsize = 8, int maximumfontsize = 48, int showeffects = 1, int showcolor = 1, int allowvectorfonts = 1, int scriptsonly = 0, int fixedpitchonly = 0, int allowcharsetchange = 1 ); [System.Runtime.InteropServices.DispId( 8 )] string Help( string dialogname = "", int html = 0 ); [System.Runtime.InteropServices.DispId( 9 )] string InputBox( string prompt = "", string title = "", string defaultanswer = "", string mask = "", int asciionly = 0, int returnunmasked = 0, string ontheflyregex = "", string endresultregex = "", int regexignorecase = 0, int hidepassword = 0, int showpwcheckbox = 0, string showpwcaption = "", int windowwidth = 200, int windowheight = 110, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ); [System.Runtime.InteropServices.DispId( 10 )] string MessageBox( string message, string title = "", string buttons = "OK", string icon = "None", int defaultbutton = 1, string options = "" ); [System.Runtime.InteropServices.DispId( 11 )] string MultipleChoiceBox( string list, string prompt = "", string title = "", string preselected = "", int rows = 0, int columns = 0, int modal = 1, int windowwidth = 200, int windowheight = 90, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ); [System.Runtime.InteropServices.DispId( 12 )] string OpenFileBox( string filter = "All files (*.*)|*.*", string folder = "", string title = "" ); [System.Runtime.InteropServices.DispId( 13 )] string OpenFolderBox( string startfolder = "", string description = "", int allowcreatenew = 0 ); [System.Runtime.InteropServices.DispId( 14 )] string PrinterSelectBox( string title = "Select Printer", string preselected = "0", string printercategory = "All", int windowwidth = 400, int windowheight = 220, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ); [System.Runtime.InteropServices.DispId( 15 )] string RadioButtonBox( string list, string prompt = "", string title = "", int defaultindex = -1, int rows = 0, int columns = 0, int modal = 1, int windowwidth = 200, int windowheight = 90, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ); [System.Runtime.InteropServices.DispId( 16 )] string SampleCode( string dialogname = "" ); [System.Runtime.InteropServices.DispId( 17 )] string SaveFileBox( string filter = "", string folder = "", string description = "", string title = "", int forceextension = 0, int overwrite = 0 ); [System.Runtime.InteropServices.DispId( 18 )] int SystemTrayMessage( string message, string title, int escapemessage = 1, int timeout = 10, string iconfile = "shell32.dll", int iconindex = 277, string tooltipicon = "Info", int wait = 1 ); [System.Runtime.InteropServices.DispId( 19 )] string Version( ); } [System.Runtime.InteropServices.Guid( "FD761AF3-C76E-4B4C-8C64-95464BDD3BCA" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )] public interface DialogBoxes_Events { } [System.Runtime.InteropServices.Guid( "2DC15C73-77DD-4766-8A60-57115DE84231" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.None ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( DialogBoxes_Events ) )] public class DialogBoxes : DialogBoxes_Interface { #region General public void CheckUpdate( ) { Global.Common.ProgramInfo.CheckUpdate( ); } public string Credits( ) { return Global.Common.Credits( ); } public string Help( string dialogname = "", int html = 0 ) { System.Collections.Generic.List classnames = System.Reflection.Assembly.GetExecutingAssembly( ).GetTypes( ).Where( t => string.Equals( t.Namespace, "RobvanderWoude", System.StringComparison.Ordinal ) && t.IsClass && ( t.Name.EndsWith( "Box" ) || t.Name.Equals( "SystemTrayMessage" ) ) ).Select( t => t.Name ).Distinct( ).ToList( ); if ( string.IsNullOrWhiteSpace( dialogname ) || !classnames.Contains( dialogname, System.StringComparer.InvariantCultureIgnoreCase ) ) { dialogname = "All"; } string help = string.Format( "{0}, Version {1}\n", Global.Common.ProgramInfo.FileName, Version( ) ); help += string.Format( "{0}\n", Global.Common.ProgramInfo.Comment ); help += string.Format( "{0}\n", Global.Common.ProgramInfo.Copyrights ); help += "https://www.robvanderwoude.com\n\n"; help += "ProgID: \"RobvanderWoude.DialogBoxes\"\n\n\n"; if ( dialogname == "All" || dialogname == "ColorSelectBox" || dialogname == "AllColorsSelectBox" || dialogname == "ConsoleColorSelectBox" ) { help += ( new ColorSelectBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "DateTimeBox" ) { help += ( new DateTimeBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "DropDownBox" ) { help += ( new DropDownBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "FontSelectBox" ) { help += ( new FontSelectBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "InputBox" ) { help += ( new InputBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "MessageBox" ) { help += ( new MessageBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "MultipleChoiceBox" ) { help += ( new MultipleChoiceBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "OpenFileBox" ) { help += ( new OpenFileBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "OpenFolderBox" ) { help += ( new OpenFolderBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "PrinterSelectBox" ) { help += ( new PrinterSelectBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "RadioButtonBox" ) { help += ( new RadioButtonBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "SaveFileBox" ) { help += ( new SaveFileBox( ) ).Help( html ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "SystemTrayMessage" ) { help += ( new SystemTrayMessage( ) ).Help( html ); } help = help.Replace( "\n", System.Environment.NewLine ); return help; } public string SampleCode( string dialogname = "" ) { System.Collections.Generic.List classnames = System.Reflection.Assembly.GetExecutingAssembly( ).GetTypes( ).Where( t => string.Equals( t.Namespace, "RobvanderWoude", System.StringComparison.Ordinal ) && t.IsClass && ( t.Name.EndsWith( "Box" ) || t.Name.Equals( "SystemTrayMessage" ) ) ).Select( t => t.Name ).Distinct( ).ToList( ); if ( string.IsNullOrWhiteSpace( dialogname ) || !classnames.Contains( dialogname, System.StringComparer.InvariantCultureIgnoreCase ) ) { dialogname = "All"; } string help = string.Format( "' {0}, Version {1}\n", Global.Common.ProgramInfo.FileName, Version( ) ); help += string.Format( "' {0}\n", Global.Common.ProgramInfo.Comment ); help += string.Format( "' {0}\n", Global.Common.ProgramInfo.Copyrights ); help += "' https://www.robvanderwoude.com\n"; help += "' ProgID: \"RobvanderWoude.DialogBoxes\"\n\n"; if ( dialogname == "All" || dialogname == "ColorSelectBox" || dialogname == "AllColorsSelectBox" || dialogname == "ConsoleColorSelectBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new ColorSelectBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "DateTimeBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new DateTimeBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "DropDownBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new DropDownBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "FontSelectBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new FontSelectBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "InputBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new InputBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "MessageBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new MessageBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "MultipleChoiceBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new MultipleChoiceBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "OpenFileBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new OpenFileBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "OpenFolderBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new OpenFolderBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "PrinterSelectBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new PrinterSelectBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "RadioButtonBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new RadioButtonBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "SaveFileBox" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new SaveFileBox( ) ).SampleCode( ); } if ( dialogname == "All" ) { help += "\n\n\n"; } if ( dialogname == "All" || dialogname == "SystemTrayMessage" ) { help += string.Format( "' {0}:\n\n", dialogname ); help += ( new SystemTrayMessage( ) ).SampleCode( ); } help = help.Replace( "\n", System.Environment.NewLine ); return help; } public string Version( ) { return Global.Common.ProgramInfo.FileVersion; } #endregion General [System.STAThread] public string AllColorsSelectBox( int allowcustomcolors = 1 ) { ColorSelectBox colorselectbox = new ColorSelectBox( ); colorselectbox.consolecolorsonly = 0; colorselectbox.allowcustomcolors = allowcustomcolors; colorselectbox.Show( ); return colorselectbox.selectedcolorname; } public string ConsoleColorSelectBox( string title = "", int timeout = 0, int left = -1, int top = -1 ) { ColorSelectBox colorselectbox = new ColorSelectBox( ); colorselectbox.consolecolorsonly = 1; colorselectbox.left = left; colorselectbox.timeout = timeout; colorselectbox.title = title; colorselectbox.top = top; colorselectbox.Show( ); return colorselectbox.selectedcolorname; } public string DateTimeBox( string title = "", string initialdt = "", string culture = "fr-CA", string dateformat = "yyyy-MM-dd", string timeformat = "HH:mm:ss", int dateonly = 0, int timeonly = 0, string earliestdate = "", string latestdate = "", int minimumoffset = 0, int maximumoffset = 0, int windowwidth = 0, int windowheight = 0, string okcaption = "OK", string cancelcaption = "Cancel" ) { DateTimeBox datetimebox = new DateTimeBox( ); datetimebox.captioncancel = cancelcaption; datetimebox.captionok = okcaption; datetimebox.culturegui = culture; datetimebox.culturein = culture; datetimebox.dateformatout = dateformat; datetimebox.dateonly = dateonly; datetimebox.earliestdate = earliestdate; datetimebox.initialdatetime = initialdt; datetimebox.latestdate = latestdate; datetimebox.maxdaysback = minimumoffset; datetimebox.maxdaysforward = maximumoffset; datetimebox.timeformatout = timeformat; datetimebox.timeonly = timeonly; datetimebox.title = title; datetimebox.windowheight = windowheight; datetimebox.windowwidth = windowwidth; datetimebox.Show( ); return datetimebox.selecteddate; } public string DropDownBox( string list, string prompt = "", string title = "", int defaultindex = -1, int modal = 1, int windowwidth = 200, int windowheight = 90, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ) { DropDownBox dropdownbox = new DropDownBox( ); dropdownbox.captioncancel = cancelcaption; dropdownbox.captionok = okcaption; dropdownbox.defaultindex = defaultindex; dropdownbox.list = list; dropdownbox.modal = modal; dropdownbox.prompt = prompt; dropdownbox.timeout = timeout; dropdownbox.title = title; dropdownbox.windowheight = windowheight; dropdownbox.windowwidth = windowwidth; dropdownbox.Show( ); return dropdownbox.selecteditem; } [System.STAThread] public string FontSelectBox( string fontname = "Courier New", int fontsize = 12, int minimumfontsize = 8, int maximumfontsize = 48, int showeffects = 1, int showcolor = 1, int allowvectorfonts = 1, int scriptsonly = 0, int fixedpitchonly = 0, int allowcharsetchange = 1 ) { FontSelectBox fontselectbox = new FontSelectBox( ); fontselectbox.fontfamily = fontname; fontselectbox.fontsize = fontsize; fontselectbox.minimumfontsize = minimumfontsize; fontselectbox.maximumfontsize = maximumfontsize; fontselectbox.showeffects = showeffects; fontselectbox.showcolor = showcolor; fontselectbox.vectorfonts = allowvectorfonts; fontselectbox.scriptsonly = scriptsonly; fontselectbox.fixedpitchonly = fixedpitchonly; fontselectbox.choosecharset = allowcharsetchange; fontselectbox.Show( ); return string.Format( "{0}, {1}, {2}", fontselectbox.fontfamily, fontselectbox.fontsize, fontselectbox.fontstyle ); } public string InputBox( string prompt = "", string title = "", string defaultanswer = "", string mask = "", int asciionly = 0, int returnunmasked = 0, string ontheflyregex = "", string endresultregex = "", int regexcasesensitive = 1, int hidepassword = 0, int showpwcheckbox = 0, string showpwcaption = "", int windowwidth = 200, int windowheight = 110, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ) { InputBox inputbox = new InputBox( ); inputbox.prompt = prompt; inputbox.title = title; inputbox.initialinput = defaultanswer; inputbox.mask = mask; inputbox.asciionly = asciionly; inputbox.regexonthefly = ontheflyregex; inputbox.regexendresult = endresultregex; inputbox.regexcasesensitive = regexcasesensitive; inputbox.hidepassword = hidepassword; inputbox.allowshowpassword = showpwcheckbox; inputbox.captionshowpassword = showpwcaption; inputbox.windowwidth = windowwidth; inputbox.windowheight = windowheight; inputbox.timeout = timeout; inputbox.captionok = okcaption; inputbox.captioncancel = cancelcaption; inputbox.Show( ); if ( returnunmasked == 1 ) { return inputbox.input; } else { return inputbox.maskedinput; } } [System.STAThread] public string MessageBox( string message, string title = "", string buttons = "OK", string icon = "None", int defaultbutton = 1, string options = "" ) { RobvanderWoude.MessageBox messagebox = new RobvanderWoude.MessageBox( ); messagebox.message = message; messagebox.title = title; messagebox.buttons = buttons; messagebox.icon = icon; messagebox.defaultbutton = defaultbutton; messagebox.options = options; messagebox.Show( ); return messagebox.buttonclicked; } public string MultipleChoiceBox( string list, string prompt = "", string title = "", string preselected = "", int rows = 0, int columns = 0, int modal = 1, int windowwidth = 200, int windowheight = 90, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ) { MultipleChoiceBox multiplechoicebox = new MultipleChoiceBox( ); if ( !list.Contains( ";" ) && System.IO.File.Exists( list ) ) { multiplechoicebox.list = string.Empty; multiplechoicebox.listfile = list; } else { multiplechoicebox.list = list; multiplechoicebox.listfile = string.Empty; } multiplechoicebox.captioncancel = cancelcaption; multiplechoicebox.captionok = okcaption; multiplechoicebox.columns = columns; multiplechoicebox.modal = modal; multiplechoicebox.preselected = preselected; multiplechoicebox.prompt = prompt; multiplechoicebox.rows = rows; multiplechoicebox.timeout = timeout; multiplechoicebox.title = title; multiplechoicebox.windowheight = windowheight; multiplechoicebox.windowwidth = windowwidth; multiplechoicebox.Show( ); return multiplechoicebox.selecteditems; } [System.STAThread] public string OpenFileBox( string filter = "All files (*.*)|*.*", string folder = "", string title = "" ) { OpenFileBox openfilebox = new OpenFileBox( ); openfilebox.addallfiles = 1; openfilebox.addextension = 1; openfilebox.filter = filter; openfilebox.multidotted = 1; openfilebox.multiselect = 0; openfilebox.showreadonly = 0; openfilebox.startfolder = folder; openfilebox.title = title; openfilebox.Show( ); return openfilebox.selectedfile; } [System.STAThread] public string OpenFolderBox( string startfolder = "", string description = "", int allowcreatenew = 0 ) { OpenFolderBox openfolderbox = new OpenFolderBox( ); openfolderbox.allowmakedir = allowcreatenew; openfolderbox.description = description; openfolderbox.rootfolder = "MyComputer"; openfolderbox.startfolder = startfolder; openfolderbox.Show( ); return openfolderbox.selectedfolder; } public string PrinterSelectBox( string title = "Select Printer", string preselected = "0", string printercategory = "All", int windowwidth = 400, int windowheight = 220, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ) { PrinterSelectBox printerselectbox = new PrinterSelectBox( ); printerselectbox.captioncancel = cancelcaption; printerselectbox.captionok = okcaption; printerselectbox.timeout = timeout; printerselectbox.title = title; printerselectbox.preselected = preselected; printerselectbox.printercategory = printercategory; printerselectbox.windowheight = windowheight; printerselectbox.windowwidth = windowwidth; printerselectbox.Show( ); return printerselectbox.selectedprinter; } public string RadioButtonBox( string list, string prompt = "", string title = "", int defaultindex = -1, int rows = 0, int columns = 0, int modal = 1, int windowwidth = 200, int windowheight = 90, int timeout = 0, string okcaption = "OK", string cancelcaption = "Cancel" ) { RadioButtonBox radiobuttonbox = new RadioButtonBox( ); if ( !list.Contains( ";" ) && System.IO.File.Exists( list ) ) { radiobuttonbox.list = string.Empty; radiobuttonbox.listfile = list; } else { radiobuttonbox.list = list; radiobuttonbox.listfile = string.Empty; } radiobuttonbox.prompt = prompt; radiobuttonbox.title = title; radiobuttonbox.defaultindex = defaultindex; radiobuttonbox.rows = rows; radiobuttonbox.columns = columns; radiobuttonbox.modal = modal; radiobuttonbox.windowwidth = windowwidth; radiobuttonbox.windowheight = windowheight; radiobuttonbox.timeout = timeout; radiobuttonbox.captioncancel = cancelcaption; radiobuttonbox.captionok = okcaption; radiobuttonbox.Show( ); return radiobuttonbox.selecteditem; } [System.STAThread] public string SaveFileBox( string filter = "", string folder = "", string description = "" , string title = "", int forceextension = 0, int overwrite = 0 ) { SaveFileBox savefilebox = new SaveFileBox( ); savefilebox.addallfiles = 1; savefilebox.addextension = 1; savefilebox.description = description; savefilebox.filter = filter; savefilebox.forceext = forceextension; savefilebox.multidotted = 1; savefilebox.overwrite = overwrite; savefilebox.startfolder = folder; savefilebox.title = title; savefilebox.Show( ); return savefilebox.selectedfile; } public int SystemTrayMessage( string message, string title, int escapemessage = 1, int timeout = 10, string iconfile = "shell32.dll", int iconindex = 277, string tooltipicon = "Info", int wait = 1 ) { SystemTrayMessage systraymessage = new SystemTrayMessage( ); systraymessage.escapemessage = escapemessage; systraymessage.iconfile = iconfile; systraymessage.iconindex = iconindex; systraymessage.message = message; systraymessage.timeout = timeout; systraymessage.title = title; systraymessage.tooltipicon = tooltipicon; systraymessage.wait = wait; systraymessage.Show( ); if ( systraymessage.wait == 1 ) { return systraymessage.balloonclicked; } else { return 0; } } } }