(view source code of dialogboxes_radiobuttonbox.cs as plain text)
using System.Linq;
namespace RobvanderWoude
{
[System.Runtime.InteropServices.Guid( "1F355F39-623F-4559-BBED-C73FA3FB470D" )]
public interface RadioButtonBox_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( "752BA062-AF40-47F6-BE1E-D7EB602672F0" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )]
public interface RadioButtonBox_Events
{
}
[System.Runtime.InteropServices.Guid( "8E8C1842-4B89-4F8B-869B-52CA93ED9A0C" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( RadioButtonBox_Events ) )]
public class RadioButtonBox : RadioButtonBox_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.Timers.Timer timer;
static System.Windows.Forms.Form radiobuttonboxform;
static System.Windows.Forms.GroupBox groupbox;
#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 += "<h1>Help for RadioButtonBox class</h1>\n\n";
help += "<p>Present a dialog with a group of radio buttons, and return the text for the selected item</p>\n\n";
help += "<h2>COM ProgID: RobvanderWoude.RadioButtonBox</h2>\n\n";
}
else
{
help += "Help for RadioButtonBox class\n";
help += new string( '\u2500', help.Length ) + "\n\n";
help += "Present a dialog with a group of radio buttons, and return the text for the selected item\n\n\n";
help += "COM ProgID: RobvanderWoude.RadioButtonBox\n\n\n";
}
#region Properties
if ( html == 1 )
{
separatorline = string.Empty;
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";
help += "<table>\n";
help += "<tr>\n";
help += "\t<th colspan=\"5\">Properties (Note that all properties are string or integer, no booleans, objects or arrays)</th>\n";
help += "</tr>\n";
help += "<tr>\n";
help += "\t<th>Property Name</th>\n";
help += "\t<th>Description</th>\n";
help += "\t<th>Mandatory</th>\n";
help += "\t<th>Read-Only</th>\n";
help += "\t<th>Default (Allowed) Values</th>\n";
help += "</tr>\n";
}
else
{
col1width = 18;
col2width = 50;
col3width = 9;
col4width = 9;
col5width = 42;
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, "columns", "The number of columns", "no", "no", "", html );
help += separatorline;
help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html );
help += separatorline;
help += HelpTableRow( linetemplate, "defaultindex", "The index of the preselected item in the list", "no", "no", "", 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 = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td colspan=\"2\" style=\"vertical-align: middle;\">{2}</td>\n\t<td>{3}</td>\n\t<td colspan=\"2\" style=\"vertical-align: middle;\">{4}</td>\n</tr>\n";
help += string.Format( template, "list", "Semicolon-separated list of items", "* YES", "no", "* Set either \"list\" or \"listfile\" property" );
template = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n</tr>\n";
help += string.Format( template, "listfile", "Path to file containing list", "no" );
}
else
{
help += HelpTableRow( linetemplate, "list", "Semicolon-separated list of items", "", "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 radio button item", "N/A", "YES", "", html );
help += separatorline;
help += HelpTableRow( linetemplate, "selecteditem", "Text of last selected radio button 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 += "</table>\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 = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n</tr>\n";
help += "<table>\n";
help += "<tr>\n";
help += "\t<th colspan=\"3\">Methods</th>\n";
help += "</tr>\n";
help += "<tr>\n";
help += "\t<th>Method Name</th>\n";
help += "\t<th>Description</th>\n";
help += "\t<th>Requirements</th>\n";
help += "</tr>\n";
}
else
{
col1width = 21;
col2width = 74;
col3width = 39;
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 dialog with a group of radio buttons based on the current property values, and saves the text for the selected item in the \"selecteditem\" property, and its index (in list) in the \"selectedindex\" property.", "", html );
if ( html == 1 )
{
help += "</table>\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 += "<h2>VBScript usage example:</h2>\n\n<pre>";
}
else
{
help += "VBScript usage example:\n";
help += new string( '\u2500', 23 ) + "\n\n";
}
help += SampleCode( );
if ( html == 1 )
{
help += "</pre>";
}
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 objRadioButtonBox = CreateObject( \"RobvanderWoude.RadioButtonBox\" )\n\n";
code += "With objRadioButtonBox\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 objRadioButtonBox = Nothing\n\n";
return code;
}
[System.STAThread]
public void Show( )
{
#region Initial Sizes
int buttonheight = 25;
int buttonwidth = 80;
int horizontalmargin = 10;
int promptheight = 20;
int promptwidth = 0;
double rbsafetyfactor = 1.05;
int rbtextheight = 0; // radiobutton text height
int rbtextwidth = 0; // radiobutton text width
int rbwidth = 15; // radiobutton width without text
int verticalmargin = 10;
#endregion Initial Sizes
#region Timer
_timeoutelapsed = false;
if ( timeout > 0 )
{
timer = new System.Timers.Timer( );
timer.Elapsed += new System.Timers.ElapsedEventHandler( RadioButtonBox_Class_Timer_Elapsed );
timer.Interval = _timeout;
timer.Start( );
}
#endregion Timer
#region Main Form
radiobuttonboxform = new System.Windows.Forms.Form( );
radiobuttonboxform.Font = new System.Drawing.Font( _fontfamily, _fontsize, System.Drawing.FontStyle.Regular );
radiobuttonboxform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
radiobuttonboxform.MaximizeBox = false;
radiobuttonboxform.MinimizeBox = false;
if ( left < 0 || top < 0 )
{
radiobuttonboxform.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
}
else
{
radiobuttonboxform.Location = new System.Drawing.Point( left, top );
radiobuttonboxform.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
}
radiobuttonboxform.Text = title;
#endregion Main Form
#region Prompt
System.Windows.Forms.Label labelPrompt = new System.Windows.Forms.Label( );
if ( string.IsNullOrWhiteSpace( prompt ) )
{
promptheight = -1 * verticalmargin;
}
else if ( _literal )
{
// leave prompt height unchanged
}
else
{
// Calculate required height for single prompt line
promptheight = System.Windows.Forms.TextRenderer.MeasureText( "Test", labelPrompt.Font ).Height;
prompt = prompt.Replace( "\\n", "\n" ).Replace( "\\r", "\r" );
labelPrompt.Text = prompt;
string[] lines = prompt.Split( "\n".ToCharArray( ) );
int promptlines = lines.Length;
foreach ( string line in lines )
{
promptwidth = System.Math.Max( promptwidth, System.Windows.Forms.TextRenderer.MeasureText( line, labelPrompt.Font ).Width );
}
// Calculate required height for multiple line prompt
promptheight = promptlines * promptheight;
}
#endregion Prompt
#region Radio Buttons
System.Collections.Generic.List<System.Windows.Forms.RadioButton> radiobuttons = new System.Collections.Generic.List<System.Windows.Forms.RadioButton>( );
for ( int i = 0; i < _list.Count; i++ )
{
System.Windows.Forms.RadioButton radiobutton = new System.Windows.Forms.RadioButton( );
radiobutton.Text = _list[i];
radiobutton.Checked = ( defaultindex == i );
rbtextwidth = System.Math.Max( rbtextwidth, System.Convert.ToInt32( System.Windows.Forms.TextRenderer.MeasureText( _list[i], radiobutton.Font ).Width * rbsafetyfactor ) );
rbtextheight = System.Math.Max( rbtextheight, System.Convert.ToInt32( System.Windows.Forms.TextRenderer.MeasureText( _list[i], radiobutton.Font ).Height * rbsafetyfactor ) );
radiobuttons.Add( radiobutton );
}
#endregion Radio Buttons
#region Buttons
System.Windows.Forms.Button okButton = new System.Windows.Forms.Button( );
okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
okButton.Name = "okButton";
okButton.Text = captionok;
System.Windows.Forms.Button cancelButton = new System.Windows.Forms.Button( );
cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
cancelButton.Name = "cancelButton";
cancelButton.Text = captioncancel;
#endregion Buttons
#region Calculate Window Layout
if ( rows > 0 ) // rows value is "leading"
{
rows = System.Math.Min( rows, _list.Count );
columns = (int) System.Math.Floor( (decimal) ( _list.Count + rows - 1 ) / rows );
}
else if ( columns > 0 ) // columns value is "leading"
{
columns = System.Math.Min( columns, _list.Count );
rows = (int) System.Math.Floor( (decimal) ( _list.Count + columns - 1 ) / columns );
}
else // single column
{
columns = 1;
rows = _list.Count;
}
int rbgroupwidth = 0;
int rbgroupheight = 0;
int rowheight = 0;
int colwidth = 0;
if ( windowwidth != defaultwindowwidth )
{
rbgroupwidth = windowwidth - 2 * horizontalmargin;
colwidth = (int) System.Math.Floor( (decimal) ( rbgroupwidth - horizontalmargin - columns * ( rbwidth + horizontalmargin ) ) / columns );
}
else
{
colwidth = rbtextwidth + rbwidth;
rbgroupwidth = System.Math.Max( defaultwindowwidth - 2 * horizontalmargin, columns * ( colwidth + horizontalmargin ) + 2 * horizontalmargin );
windowwidth = System.Math.Max( defaultwindowwidth, rbgroupwidth + 2 * horizontalmargin );
}
if ( windowheight != defaultwindowheight )
{
rbgroupheight = windowheight - promptheight - buttonheight - 4 * verticalmargin;
rowheight = (int) System.Math.Floor( (decimal) ( rbgroupheight - 2 * verticalmargin ) / rows );
}
else
{
rowheight = rbtextheight + verticalmargin;
windowheight = System.Math.Max( defaultwindowheight, 6 * verticalmargin + promptheight + buttonheight + rows * rowheight );
rbgroupheight = rows * rowheight + 2 * verticalmargin;
}
#endregion Calculate Window Layout
#region Check Available Group Box Space
if ( rbgroupheight / rows < rowheight || rbgroupwidth / columns < colwidth )
{
_errors.Add( timestamp + "Window size too small to display all radio buttons; increase window size, reduce or remove prompt, and/or change number of rows and columns" );
}
#endregion Check Available Group Box Space
#region Build Form
System.Drawing.Size windowsize = new System.Drawing.Size( windowwidth, windowheight );
radiobuttonboxform.ClientSize = windowsize;
if ( !string.IsNullOrWhiteSpace( prompt ) )
{
labelPrompt.Size = new System.Drawing.Size( windowwidth - 2 * horizontalmargin, promptheight );
labelPrompt.Location = new System.Drawing.Point( horizontalmargin, verticalmargin );
radiobuttonboxform.Controls.Add( labelPrompt );
}
groupbox = new System.Windows.Forms.GroupBox( );
groupbox.Size = new System.Drawing.Size( rbgroupwidth, rbgroupheight );
groupbox.Location = new System.Drawing.Point( horizontalmargin, promptheight + 2 * verticalmargin );
foreach ( System.Windows.Forms.RadioButton radiobutton in radiobuttons )
{
groupbox.Controls.Add( radiobutton );
}
radiobuttonboxform.Controls.Add( groupbox );
for ( int row = 0; row < rows; row++ )
{
for ( int column = 0; column < columns; column++ )
{
int index = row * columns + column;
if ( index < radiobuttons.Count )
{
int x = System.Convert.ToInt32( horizontalmargin + column * ( colwidth + horizontalmargin ) );
int y = System.Convert.ToInt32( verticalmargin + row * rowheight );
radiobuttons[index].Size = new System.Drawing.Size( colwidth + horizontalmargin, rowheight );
radiobuttons[index].Location = new System.Drawing.Point( x, y );
radiobuttons[index].CheckedChanged += new System.EventHandler( RadioButtonBox_Class_CheckedChanged );
}
}
}
okButton.Size = new System.Drawing.Size( buttonwidth, buttonheight );
okButton.Location = new System.Drawing.Point( windowwidth / 2 - horizontalmargin - buttonwidth, windowheight - buttonheight - verticalmargin );
radiobuttonboxform.Controls.Add( okButton );
cancelButton.Size = new System.Drawing.Size( buttonwidth, buttonheight );
cancelButton.Location = new System.Drawing.Point( windowwidth / 2 + horizontalmargin, windowheight - buttonheight - verticalmargin );
radiobuttonboxform.Controls.Add( cancelButton );
radiobuttonboxform.AcceptButton = okButton; // OK on Enter
radiobuttonboxform.CancelButton = cancelButton; // Cancel on Esc
#endregion Build Form
#region Show Dialog
radiobuttonboxform.TopMost = topmost;
System.Windows.Forms.DialogResult result = radiobuttonboxform.ShowDialog( );
if ( !_timeoutelapsed && result == System.Windows.Forms.DialogResult.Cancel )
{
_selecteditem = string.Empty;
_selectedindex = -1;
}
#endregion Show Dialog
}
#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 int _columns = 0;
[System.Runtime.InteropServices.ComVisible( true )]
public int columns
{
get
{
return _columns;
}
set
{
_columns = value;
}
}
private System.Collections.Generic.List<string> _debuginfo = new System.Collections.Generic.List<string>( );
[System.Runtime.InteropServices.ComVisible( true )]
public string debuginfo
{
get
{
return string.Join( "\n", _debuginfo.ToArray( ) );
}
}
private int _defaultindex = 0;
[System.Runtime.InteropServices.ComVisible( true )]
public int defaultindex
{
get
{
return _defaultindex;
}
set
{
_defaultindex = value;
}
}
private System.Collections.Generic.List<string> _errors = new System.Collections.Generic.List<string>( );
[System.Runtime.InteropServices.ComVisible( true )]
public string errors
{
get
{
return string.Join( "\n", _errors.ToArray( ) );
}
}
private static bool _fixedpitchonly = false;
[System.Runtime.InteropServices.ComVisible( true )]
public int fixedpitchonly
{
get
{
return ( _fixedpitchonly ? 1 : 0 );
}
set
{
_fixedpitchonly = ( value == 1 );
if ( _fixedpitchonly)
{
_fontfamily = System.Drawing.FontFamily.GenericMonospace;
}
}
}
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, _fixedpitchonly );
}
}
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 System.Collections.Generic.List<string> _list = new System.Collections.Generic.List<string>( );
[System.Runtime.InteropServices.ComVisible( true )]
public string list
{
get
{
return string.Join( ";", _list );
}
set
{
_list = value.Split( ";\n".ToCharArray( ), System.StringSplitOptions.RemoveEmptyEntries ).Select( i => i.Trim( ) ).ToList<string>( );
}
}
[System.Runtime.InteropServices.ComVisible( true )]
public string listfile
{
get
{
return string.Join( ";", _list );
}
set
{
if ( System.IO.File.Exists( value ) )
{
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( timestamp + "Invalid list file content" );
}
_list = text.Split( ";\n\r".ToCharArray( ), System.StringSplitOptions.RemoveEmptyEntries ).Select( i => i.Trim( ) ).ToList<string>( );
}
catch ( System.Exception e )
{
_errors.Add( timestamp + "Unable to open list file: " + e.Message );
}
}
else
{
_errors.Add( timestamp + "List file not found" );
}
}
}
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 _rows = 0;
[System.Runtime.InteropServices.ComVisible( true )]
public int rows
{
get
{
return _rows;
}
set
{
_rows = value;
}
}
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 (int) ( _timeout / 1000 );
}
set
{
if ( value < 0 || value > 3600 )
{
_timeout = 0;
}
else
{
_timeout = value * 1000;
}
}
}
private bool _timeoutelapsed = false;
[System.Runtime.InteropServices.ComVisible( true )]
public int timeoutelapsed
{
get
{
return ( _timeoutelapsed ? 1 : 0 );
}
}
private 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 RadioButtonBox_Class_CheckedChanged( object sender, System.EventArgs e )
{
foreach ( System.Windows.Forms.RadioButton rb in groupbox.Controls )
{
if ( rb.Checked )
{
_selecteditem = rb.Text;
_selectedindex = _list.IndexOf( selecteditem );
break;
}
}
}
private void RadioButtonBox_Class_Timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e )
{
_timeoutelapsed = true;
foreach ( System.Windows.Forms.RadioButton rb in groupbox.Controls )
{
if ( rb.Checked )
{
_selecteditem = rb.Text;
_selectedindex = _list.IndexOf( selecteditem );
break;
}
}
radiobuttonboxform.Close( );
}
#endregion Event Handlers
}
}
page last modified: 2024-04-16; loaded in 0.0454 seconds