Last active
February 20, 2020 23:13
-
-
Save xepherys/0c2ff5972ba381672791be035b48ebe8 to your computer and use it in GitHub Desktop.
Extended Windows Forms Controls for Visual Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Runtime.Serialization; | |
using System.Security.Permissions; | |
using System.Windows.Forms; | |
namespace Xeph.Windows.Forms.ExtendedControls | |
{ | |
public class ExtendedControlListener | |
{ | |
private static readonly Lazy<ExtendedControlListener> lazy = new Lazy<ExtendedControlListener>(() => new ExtendedControlListener()); | |
List<IExtendedControl> extendedControls = new List<IExtendedControl>(); | |
#region Constructors | |
private ExtendedControlListener() { } | |
public static ExtendedControlListener Instance | |
{ | |
get | |
{ | |
return lazy.Value; | |
} | |
} | |
#endregion | |
#region Properties | |
public List<IExtendedControl> ExtendedControls | |
{ | |
get | |
{ | |
return this.extendedControls; | |
} | |
} | |
#endregion | |
#region Methods | |
public void Add(IExtendedControl c) | |
{ | |
extendedControls.Add(c); | |
} | |
public void Clear() | |
{ | |
extendedControls.Clear(); | |
} | |
public IExtendedControl Get(string name) | |
{ | |
IExtendedControl _ret = null; | |
_ret = extendedControls.Single(s => s.ValueName == name); | |
return _ret; | |
} | |
public Control GetControl(string name) | |
{ | |
Control _ret = null; | |
_ret = extendedControls.Single(s => s.ValueName == name) as Control; | |
return _ret; | |
} | |
public List<IExtendedControl> ConfigItems() | |
{ | |
List<IExtendedControl> _ret = new List<IExtendedControl>(); | |
_ret = extendedControls.Where(w => w.ConfigValue == true).ToList(); | |
return _ret; | |
} | |
public List<IExtendedControl> SettingItems() | |
{ | |
List<IExtendedControl> _ret = new List<IExtendedControl>(); | |
_ret = extendedControls.Where(w => w.SaveSessionObject == true).ToList(); | |
return _ret; | |
} | |
#endregion | |
#region Vanity Methods | |
public DateTime GetDate(string name) | |
{ | |
DateTime _ret = DateTime.Now; | |
try | |
{ | |
Control c = (extendedControls.Single(s => s.ValueName == name) as Control); | |
if (c.GetType() == typeof(ExtendedDateTimePicker)) | |
_ret = (DateTime)GetEDateTimeValue(c); | |
else | |
throw new Exception(); | |
} | |
catch | |
{ | |
throw new InvalidCastException(String.Format("Invalid cast fetching .Value value for {0}.\nExtendedControllerListener.GetDate()", name)); | |
} | |
return _ret; | |
} | |
public string GetString(string name) | |
{ | |
string _ret = String.Empty; | |
try | |
{ | |
Control c = (extendedControls.Single(s => s.ValueName == name) as Control); | |
if (c.GetType() == typeof(ExtendedComboBox)) | |
_ret = (string)GetEComboBoxValue(c); | |
else if (c.GetType() == typeof(ExtendedTextBox)) | |
_ret = (string)GetETextBoxValue(c); | |
else | |
throw new Exception(); | |
} | |
catch | |
{ | |
throw new InvalidCastException(String.Format("Invalid cast fetching .Text value for {0}.\nExtendedControllerListener.GetString()", name)); | |
} | |
return _ret; | |
} | |
public int GetValueNum(string name) | |
{ | |
int _ret = 0; | |
try | |
{ | |
Control c = (extendedControls.Single(s => s.ValueName == name) as Control); | |
if (c.GetType() == typeof(ExtendedNumericUpDown)) | |
_ret = (int)GetENumUpDownValue(c); | |
else if (c.GetType() == typeof(ExtendedTrackBar)) | |
_ret = (int)GetETrackBarValue(c); | |
else | |
throw new Exception(); | |
} | |
catch | |
{ | |
throw new InvalidCastException(String.Format("Invalid cast fetching .Value value for {0}.\nExtendedControllerListener.GetValueNum()", name)); | |
} | |
return _ret; | |
} | |
public bool GetEnabled(string name) | |
{ | |
bool _ret = false; | |
try | |
{ | |
Control c = (extendedControls.Single(s => s.ValueName == name) as Control); | |
_ret = (bool)GetEEnabledValue(c); | |
} | |
catch | |
{ | |
throw new InvalidCastException(String.Format("Invalid cast fetching .Enabled value for {0}.\nExtendedControllerListener.GetEnabled()", name)); | |
} | |
return _ret; | |
} | |
public bool GetChecked(string name) | |
{ | |
bool _ret = false; | |
try | |
{ | |
Control c = (extendedControls.Single(s => s.ValueName == name) as Control); | |
if (c.GetType() == typeof(ExtendedCheckBox)) | |
_ret = (bool)GetECheckBoxValue(c); | |
else | |
throw new Exception(); | |
} | |
catch | |
{ | |
throw new InvalidCastException(String.Format("Invalid cast fetching .Checked value for {0}.\nExtendedControllerListener.GetChecked()", name)); | |
} | |
return _ret; | |
} | |
public T GetEnumValue<T>(string name) | |
{ | |
T _ret; | |
try | |
{ | |
Control c = (extendedControls.Single(s => s.ValueName == name) as Control); | |
if (c.GetType() == typeof(ExtendedEnumSelector)) | |
_ret = (T)Enum.Parse(typeof(T), GetEComboBoxValue(c)); | |
else | |
throw new Exception(); | |
} | |
catch | |
{ | |
throw new InvalidCastException(String.Format("Invalid cast fetching Enum value for {0}.\nExtendedControllerListener.GetEnumValue<{1}>()", name, typeof(T).ToString())); | |
} | |
return _ret; | |
} | |
#endregion | |
#region Delegates | |
delegate int GetETrackBarValueCallback(Control c); | |
private int GetETrackBarValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetETrackBarValueCallback cb = new GetETrackBarValueCallback(GetETrackBarValue); | |
return (int)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (int)(c as TrackBar).Value; | |
} | |
} | |
delegate int GetENumUpDownValueCallback(Control c); | |
private int GetENumUpDownValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetENumUpDownValueCallback cb = new GetENumUpDownValueCallback(GetENumUpDownValue); | |
return (int)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (int)(c as NumericUpDown).Value; | |
} | |
} | |
delegate string GetEComboBoxValueCallback(Control c); | |
private string GetEComboBoxValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetEComboBoxValueCallback cb = new GetEComboBoxValueCallback(GetEComboBoxValue); | |
return (string)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (string)(c as ComboBox).Text; | |
} | |
} | |
delegate string GetETextBoxValueCallback(Control c); | |
private string GetETextBoxValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetETextBoxValueCallback cb = new GetETextBoxValueCallback(GetETextBoxValue); | |
return (string)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (string)(c as TextBox).Text; | |
} | |
} | |
delegate bool GetECheckBoxValueCallback(Control c); | |
private bool GetECheckBoxValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetECheckBoxValueCallback cb = new GetECheckBoxValueCallback(GetECheckBoxValue); | |
return (bool)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (bool)(c as CheckBox).Checked; | |
} | |
} | |
delegate bool GetEEnabledCallback(Control c); | |
private bool GetEEnabledValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetEEnabledCallback cb = new GetEEnabledCallback(GetEEnabledValue); | |
return (bool)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (bool)(c as Control).Enabled; | |
} | |
} | |
delegate DateTime GetEDateTimeValueCallback(Control c); | |
private DateTime GetEDateTimeValue(Control c) | |
{ | |
if (c.InvokeRequired) | |
{ | |
GetEDateTimeValueCallback cb = new GetEDateTimeValueCallback(GetEDateTimeValue); | |
return (DateTime)c.Invoke(cb, c); | |
} | |
else | |
{ | |
return (DateTime)(c as DateTimePicker).Value; | |
} | |
} | |
#endregion | |
} | |
public interface IExtendedControl | |
{ | |
bool ConfigValue { get; set; } | |
bool SaveSessionObject { get; set; } | |
string ValueName { get; set; } | |
Type ValueType { get; } | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedCheckBox : CheckBox, IExtendedControl, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedCheckBox() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(bool); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedCheckBox(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedCheckBox iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedCheckBox; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Checked = info.GetBoolean("✓"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("✓", Checked); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedTextBox : TextBox, IExtendedControl, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedTextBox() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(string); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedTextBox(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedTextBox iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedTextBox; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Text = info.GetString("str"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("str", Text); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedRadioButton : RadioButton, IExtendedControl | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedRadioButton() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(bool); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedRadioButton(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedRadioButton iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedRadioButton; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Checked = info.GetBoolean("✓"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("✓", Checked); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedDateTimePicker : DateTimePicker, IExtendedControl, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedDateTimePicker() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(DateTime); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedDateTimePicker(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedDateTimePicker iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedDateTimePicker; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Value = info.GetDateTime("dt"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("dt", Value); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedComboBox : ComboBox, IExtendedControl, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedComboBox() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(int); // SelectedIndex | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedComboBox(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedComboBox iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedComboBox; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.SelectedIndex = info.GetInt32("idx"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("idx", SelectedIndex); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedNumericUpDown : NumericUpDown, IExtendedControl, ISupportInitialize, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedNumericUpDown() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(int); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedNumericUpDown(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedNumericUpDown iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedNumericUpDown; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Value = info.GetDecimal("val"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("val", Value); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedTrackBar : TrackBar, IExtendedControl, ISupportInitialize, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedTrackBar() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
this.valueType = typeof(int); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedTrackBar(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedTrackBar iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedTrackBar; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Value = info.GetInt32("val"); | |
iec.Enabled = info.GetBoolean("@"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("vT", valueType); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("val", Value); | |
info.AddValue("@", Enabled); | |
} | |
#endregion | |
} | |
[ComVisible(true)] | |
[Serializable] | |
public class ExtendedEnumSelector : ComboBox, IExtendedControl, ISerializable | |
{ | |
#region Fields | |
bool isConfig; // Is this a configuration option that will be checked later? | |
bool isSaved; // Should SettingsManager save this value between sessions? | |
string valueName; // Name of value for recall as configuration | |
Type valueType; | |
string valueTypeString; | |
string defaultValueText; // If this should have a default value selected, add the string value. | |
#endregion | |
#region Properties | |
[Description("Configuration value for use"), Category("Configuration")] | |
public bool ConfigValue | |
{ | |
get | |
{ | |
return this.isConfig; | |
} | |
set | |
{ | |
this.isConfig = value; | |
} | |
} | |
[Description("Value saved between sessions"), Category("Configuration")] | |
public bool SaveSessionObject | |
{ | |
get | |
{ | |
return this.isSaved; | |
} | |
set | |
{ | |
this.isSaved = value; | |
} | |
} | |
[Description("Name of value"), Category("Configuration")] | |
public string ValueName | |
{ | |
get | |
{ | |
return this.valueName; | |
} | |
set | |
{ | |
this.valueName = value; | |
} | |
} | |
[Description("Type of value saved"), Category("Configuration")] | |
public Type ValueType | |
{ | |
get | |
{ | |
return this.valueType; | |
} | |
} | |
[Description("Value string"), Category("Configuration")] | |
public string ValueTypeString | |
{ | |
get | |
{ | |
return this.valueTypeString; | |
} | |
set | |
{ | |
this.valueTypeString = value; | |
this.valueType = Type.GetType(value); | |
if (valueType != null) | |
PopulateComboBox(); | |
} | |
} | |
[Description("Default value (as string)"), Category("Configuration")] | |
public string DefaultValue | |
{ | |
get | |
{ | |
return this.defaultValueText; | |
} | |
set | |
{ | |
this.defaultValueText = value; | |
if (String.IsNullOrEmpty((this as ComboBox).SelectedText)) | |
(this as ComboBox).SelectedText = this.defaultValueText; | |
} | |
} | |
#endregion | |
#region Constructor | |
public ExtendedEnumSelector() : base() | |
{ | |
ExtendedControlListener.Instance.Add(this); | |
} | |
#endregion | |
#region Serialization | |
protected ExtendedEnumSelector(SerializationInfo info, StreamingContext context) | |
{ | |
ExtendedEnumSelector iec = ExtendedControlListener.Instance.ExtendedControls.Single(s => s.ValueName == info.GetString("vN")) as ExtendedEnumSelector; | |
iec.ConfigValue = info.GetBoolean("c?"); | |
iec.SaveSessionObject = info.GetBoolean("s?"); | |
iec.Enabled = info.GetBoolean("@"); | |
iec.SelectedIndex = info.GetInt32("idx"); | |
iec.ValueTypeString = info.GetString("vtS"); | |
} | |
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] | |
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
info.AddValue("vN", valueName); | |
info.AddValue("c?", isConfig); | |
info.AddValue("s?", isSaved); | |
info.AddValue("n", Name); | |
info.AddValue("idx", SelectedIndex); | |
info.AddValue("@", Enabled); | |
info.AddValue("vtS", ValueTypeString); | |
} | |
#endregion | |
#region Methods | |
void PopulateComboBox() | |
{ | |
this.Items.Clear(); | |
foreach (string value in Enum.GetNames(valueType)) | |
{ | |
this.Items.Add(value); | |
} | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment