using System.Linq; namespace RobvanderWoude { [System.Runtime.InteropServices.Guid( "3AC0686B-1892-4886-837F-E5B7DA47C8F8" )] public interface FontSelectBox_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 ListColors( ); [System.Runtime.InteropServices.DispId( 5 )] string ListFontCharSets( ); [System.Runtime.InteropServices.DispId( 6 )] string ListProperties( ); [System.Runtime.InteropServices.DispId( 7 )] string SampleCode( ); [System.Runtime.InteropServices.DispId( 8 )] void Show( ); } [System.Runtime.InteropServices.Guid( "35867F16-1A9E-4CD0-AA46-869A8A30E745" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )] public interface FontSelectBox_Events { } [System.Runtime.InteropServices.Guid( "8194D25A-B967-4B94-ABE6-E51BA5D1526F" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( FontSelectBox_Events ) )] public class FontSelectBox : FontSelectBox_Interface { #region Default Values static readonly FontCharSet defaultcharset = FontCharSet.ANSI; static readonly System.Drawing.Color defaultcolor = System.Drawing.Color.Black; static readonly System.Drawing.FontFamily defaultfontfamily = System.Drawing.FontFamily.GenericSansSerif; const float defaultfontsize = 10; static readonly System.Drawing.FontStyle defaultfontstyle = System.Drawing.FontStyle.Regular; const int defaultmaxfontsize = 64; const int defaultminfonstsize = 6; #endregion Default Values #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 FontSelectBox class

\n\n"; help += "

Present a font dialog, and return the selected font

\n\n"; help += "

COM ProgID: RobvanderWoude.FontSelectBox

\n\n"; } else { help += "Help for FontSelectBox class\n"; help += new string( '\u2500', help.Length ) + "\n\n"; help += "Present a font dialog, and return the selected font\n\n\n"; help += "COM ProgID: RobvanderWoude.FontSelectBox\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, "choosecharset", "Allow alternative character sets (0=false; 1=true)", "no", "no", "1: allow", html ); help += separatorline; help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "fixedpitchonly", Global.Common.Help.fixedpitchonly, "no", "no", "0: allow proportional fonts as well", html ); help += separatorline; help += HelpTableRow( linetemplate, "fontcharset", "Font character set used in dialog", "no", "no", defaultcharset.ToString( ), html ); help += separatorline; help += HelpTableRow( linetemplate, "fontcolorB", "Blue component of font color", "no", "no", "0", html ); help += separatorline; help += HelpTableRow( linetemplate, "fontcolorG", "Green component of font color", "no", "no", "0", html ); help += separatorline; help += HelpTableRow( linetemplate, "fontcolorname", "Name of font color", "no", "no", defaultcolor.Name, html ); help += separatorline; help += HelpTableRow( linetemplate, "fontcolorR", "Red component of font color", "no", "no", "0", html ); help += separatorline; help += HelpTableRow( linetemplate, "fontcolorRGB", "RGB values of font color", "no", "no", "0,0,0", 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, "fontstyle", "Font stylee used in dialog", "no", "no", "Regular (Bold, Italic, StrikeOut, UnderLine)", html ); help += separatorline; help += HelpTableRow( linetemplate, "maximumfontsize", "Maximum font size allowed in dialog", "no", "no", defaultmaxfontsize.ToString( ), html ); help += separatorline; help += HelpTableRow( linetemplate, "minimumfontsize", "Minimum font size allowed in dialog", "no", "no", defaultminfonstsize.ToString( ), html ); help += separatorline; help += HelpTableRow( linetemplate, "modal", Global.Common.Help.modal, "no", "no", "1: always on top", html ); help += separatorline; help += HelpTableRow( linetemplate, "scriptsonly", "Disable non-OEM & symbol fonts (0=false; 1=true)", "no", "no", "0: allow all", html ); help += separatorline; help += HelpTableRow( linetemplate, "showcolor", "Allow color choice in dialog (0=false; 1=true)\n(requires showeffects = 1)", "no", "no", "1: allow", html ); help += separatorline; help += HelpTableRow( linetemplate, "showeffects", "Allow underline, strikethrough (0=false; 1=true)", "no", "no", "1: allow", html ); help += separatorline; help += HelpTableRow( linetemplate, "vectorfonts", "Allow vector fonts in the dialog (0=false; 1=true)", "no", "no", "1: allow", html ); help += separatorline; help += HelpTableRow( linetemplate, "Version", Global.Common.Help.version, "N/A", "YES", "", html ); if ( html == 1 ) { help += "
Properties (Note that all properties are string or integer, no booleans, objects or arrays)
Property NameDescriptionMandatoryRead-OnlyDefault (Allowed) Values
\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, "ListColors", "Returns a semicolon-separated list of all available color names", "", html ); help += separatorline; help += HelpTableRow( linetemplate, "ListFontCharSets", "Returns a semicolon-separated list of available font character sets", "", 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 font dialog based on the current property values, and if \"OK\" is clicked, saves the selected font properties in the \"fontfamily\", \"fontsize\", \"fontstyle\", \"fontcharset\", \"fontcolorname\", \"fontcolorRGB\", \"fontcolorR\", \"fontcolorG\" and \"fontcolorB\" properties (if \"Cancel\" is clicked, the default font and properties are selected).", "", 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 ListColors( ) { return string.Join( ";", System.Enum.GetNames( typeof( System.Drawing.Color ) ) ); } public string ListFontCharSets( ) { return string.Join( ";", System.Enum.GetNames( typeof( FontCharSet ) ) ); } public string ListProperties( ) { return Global.Common.Lists.Properties( this ); } public string SampleCode( ) { string code = "Set objFontSelectBox = CreateObject( \"RobvanderWoude.FontSelectBox\" )\n\n"; code += "With objFontSelectBox\n"; code += "\t.Show\n"; code += "\tWScript.Echo .ListProperties( )\n"; code += "End With\n\n"; code += "Set objFontSelectBox = Nothing"; return code; } public void Show( ) { System.Drawing.Font font = new System.Drawing.Font( fontfamily, fontsize ); System.Windows.Forms.FontDialog fontdialog = null; try { fontdialog = new System.Windows.Forms.FontDialog { AllowScriptChange = _choosecharset, AllowVectorFonts = _vectorfonts, AllowVerticalFonts = false, FixedPitchOnly = _fixedpitchonly, Font = font, FontMustExist = true, MaxSize = maximumfontsize, MinSize = minimumfontsize, ScriptsOnly = _scriptsonly, ShowApply = false, ShowColor = _showcolor, ShowEffects = _showeffects }; } catch ( System.Exception e ) { _errors.Add( Global.Common.TimeStamp( ) + "Error while trying to build Font Dialog: " + e.Message ); } try { if ( fontdialog.ShowDialog( ) == System.Windows.Forms.DialogResult.OK ) { System.Drawing.Font selectedfont = fontdialog.Font; _fontcharset = (FontCharSet) fontdialog.Font.GdiCharSet; _fontcolor = fontdialog.Color; _fontfamily = selectedfont.FontFamily; _fontsize = selectedfont.Size; _fontstyle = selectedfont.Style; } else { _fontcharset = defaultcharset; _fontcolor = defaultcolor; _fontfamily = defaultfontfamily; _fontsize = defaultfontsize; _fontstyle = defaultfontstyle; _debuginfo.Add( timestamp + "No choice was made, using default font and properties" ); } } catch ( System.Exception e ) { _errors.Add( Global.Common.TimeStamp( ) + "Error while trying to show Font Dialog and parse the results: " + e.Message ); } } #endregion Methods #region Properties private bool _choosecharset = true; [System.Runtime.InteropServices.ComVisible( true )] public int choosecharset { get { return ( _choosecharset ? 1 : 0 ); } set { _choosecharset = ( value == 1 ); } } 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 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 bool _fixedpitchonly = false; [System.Runtime.InteropServices.ComVisible( true )] public int fixedpitchonly { get { return ( _fixedpitchonly ? 1 : 0 ); } set { _fixedpitchonly = ( value == 1 ); } } private static FontCharSet _fontcharset = defaultcharset; [System.Runtime.InteropServices.ComVisible( true )] public string fontcharset { get { return _fontcharset.ToString( ); } set { _fontcharset = Global.Common.Validate.FontCharSet( value ); } } private static System.Drawing.Color _fontcolor = defaultcolor; [System.Runtime.InteropServices.ComVisible( true )] public int fontcolorB { get { return (int) _fontcolor.B; } set { System.Array colorsarray = System.Enum.GetValues( typeof( System.Drawing.Color ) ); System.Collections.Generic.List colorslist = colorsarray.OfType( ).ToList( ); _fontcolor = colorslist.Where( c => ( c.R.Equals( _fontcolor.R ) && c.G.Equals( _fontcolor.G ) && c.B.Equals( value.LimitToRange( 0, 255 ) ) ) ).First( ); } } [System.Runtime.InteropServices.ComVisible( true )] public int fontcolorG { get { return (int) _fontcolor.G; } set { System.Array colorsarray = System.Enum.GetValues( typeof( System.Drawing.Color ) ); System.Collections.Generic.List colorslist = colorsarray.OfType( ).ToList( ); _fontcolor = colorslist.Where( c => ( c.R.Equals( _fontcolor.R ) && c.G.Equals( value.LimitToRange( 0, 255 ) ) && c.B.Equals( _fontcolor.B ) ) ).First( ); } } [System.Runtime.InteropServices.ComVisible( true )] public string fontcolorname { get { return _fontcolor.Name; } set { _fontcolor = Global.Common.Validate.ColorName( value, defaultcolor ); } } [System.Runtime.InteropServices.ComVisible( true )] public int fontcolorR { get { return (int) _fontcolor.R; } set { System.Array colorsarray = System.Enum.GetValues( typeof( System.Drawing.Color ) ); System.Collections.Generic.List colorslist = colorsarray.OfType( ).ToList( ); _fontcolor = colorslist.Where( c => ( c.R.Equals( value.LimitToRange( 0, 255 ) ) && c.G.Equals( _fontcolor.G ) && c.B.Equals( _fontcolor.B ) ) ).First( ); } } [System.Runtime.InteropServices.ComVisible( true )] public string fontcolorRGB { get { return string.Format( "{0},{1},{2}", fontcolorR, fontcolorG, fontcolorB ); } set { _fontcolor = Global.Common.Validate.ColorRGB( fontcolorRGB, defaultcolor ); } } private static 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 static 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 static System.Drawing.FontStyle _fontstyle = defaultfontstyle; [System.Runtime.InteropServices.ComVisible( true )] public string fontstyle { get { return _fontstyle.ToString( ); } set { _fontstyle = Global.Common.Validate.FontStyle( value ); } } private float _maximumfontsize = defaultmaxfontsize; [System.Runtime.InteropServices.ComVisible( true )] public int maximumfontsize { get { return System.Convert.ToInt32( _maximumfontsize ); } set { _maximumfontsize = System.Convert.ToSingle( value ); } } private float _minimumfontsize = defaultminfonstsize; [System.Runtime.InteropServices.ComVisible( true )] public int minimumfontsize { get { return System.Convert.ToInt32( _minimumfontsize ); } set { _minimumfontsize = System.Convert.ToSingle( value ); } } private bool topmost = true; [System.Runtime.InteropServices.ComVisible( true )] public int modal { get { return ( topmost ? 1 : 0 ); } set { topmost = ( value == 1 ); } } private bool _scriptsonly = false; [System.Runtime.InteropServices.ComVisible( true )] public int scriptsonly { get { return ( _scriptsonly ? 1 : 0 ); } set { _scriptsonly = ( value == 1 ); } } private bool _showcolor = true; [System.Runtime.InteropServices.ComVisible( true )] public int showcolor { get { return ( _showcolor ? 1 : 0 ); } set { _showcolor = ( value == 1 ); } } private bool _showeffects = true; [System.Runtime.InteropServices.ComVisible( true )] public int showeffects { get { return ( _showeffects ? 1 : 0 ); } set { _showeffects = ( value == 1 ); } } public static string timestamp => Global.Common.TimeStamp( ); private bool _vectorfonts = true; [System.Runtime.InteropServices.ComVisible( true )] public int vectorfonts { get { return ( _vectorfonts ? 1 : 0 ); } set { _vectorfonts = ( value == 1 ); } } [System.Runtime.InteropServices.ComVisible( true )] public string Version { get { return Global.Common.ProgramInfo.FileVersion; } } #endregion Properties } }