DotNet 4.8.1 build of DotNetBar
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#if FRAMEWORK20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.Design;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Validator;
|
||||
|
||||
namespace DevComponents.DotNetBar.Design
|
||||
{
|
||||
internal class HighlighterDesigner : ComponentDesigner
|
||||
{
|
||||
#region Internal Implementation
|
||||
public override void Initialize(IComponent component)
|
||||
{
|
||||
base.Initialize(component);
|
||||
if (!component.Site.DesignMode)
|
||||
return;
|
||||
|
||||
#if !TRIAL
|
||||
IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
dh.LoadComplete += new EventHandler(dh_LoadComplete);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FRAMEWORK20
|
||||
public override void InitializeNewComponent(IDictionary defaultValues)
|
||||
{
|
||||
base.InitializeNewComponent(defaultValues);
|
||||
SetDesignTimeDefaults();
|
||||
}
|
||||
#else
|
||||
public override void OnSetComponentDefaults()
|
||||
{
|
||||
base.OnSetComponentDefaults();
|
||||
SetDesignTimeDefaults();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void SetDesignTimeDefaults()
|
||||
{
|
||||
Highlighter highlighter = this.Component as Highlighter;
|
||||
if (highlighter == null)
|
||||
return;
|
||||
|
||||
#if !TRIAL
|
||||
string key = GetLicenseKey();
|
||||
highlighter.LicenseKey = key;
|
||||
#endif
|
||||
// Create and assign error provider
|
||||
IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
{
|
||||
highlighter.ContainerControl = dh.RootComponent as Control;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Licensing
|
||||
#if !TRIAL
|
||||
private string GetLicenseKey()
|
||||
{
|
||||
string key = "";
|
||||
Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.LocalMachine;
|
||||
regkey = regkey.OpenSubKey("Software\\DevComponents\\Licenses", false);
|
||||
if (regkey != null)
|
||||
{
|
||||
object keyValue = regkey.GetValue("DevComponents.DotNetBar.DotNetBarManager2");
|
||||
if (keyValue != null)
|
||||
key = keyValue.ToString();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
private void dh_LoadComplete(object sender, EventArgs e)
|
||||
{
|
||||
IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
dh.LoadComplete -= new EventHandler(dh_LoadComplete);
|
||||
|
||||
string key = GetLicenseKey();
|
||||
Highlighter highlighter = this.Component as Highlighter;
|
||||
if (key != "" && highlighter != null && highlighter.LicenseKey == "" && highlighter.LicenseKey != key)
|
||||
TypeDescriptor.GetProperties(highlighter)["LicenseKey"].SetValue(highlighter, key);
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,77 @@
|
||||
#if FRAMEWORK20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using DevComponents.DotNetBar.Validator;
|
||||
|
||||
namespace DevComponents.DotNetBar.Design
|
||||
{
|
||||
public class RequiredFieldValidatorConverter : ExpandableObjectConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates new instance of the class.
|
||||
/// </summary>
|
||||
public RequiredFieldValidatorConverter() { }
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether conversion can be made to specified type.
|
||||
/// </summary>
|
||||
/// <param name="context">Context Information.</param>
|
||||
/// <param name="destinationType">Destination type.</param>
|
||||
/// <returns></returns>
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(InstanceDescriptor))
|
||||
return true;
|
||||
return base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts object to specified type.
|
||||
/// </summary>
|
||||
/// <param name="context">Context information.</param>
|
||||
/// <param name="culture">Culture information.</param>
|
||||
/// <param name="value">Object to convert.</param>
|
||||
/// <param name="destinationType">Destination type.</param>
|
||||
/// <returns>Object converted to destination type.</returns>
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
|
||||
{
|
||||
if (destinationType == null)
|
||||
throw new ArgumentNullException("destinationType");
|
||||
|
||||
if ((destinationType == typeof(InstanceDescriptor)) && (value is RequiredFieldValidator))
|
||||
{
|
||||
RequiredFieldValidator validator = (RequiredFieldValidator)value;
|
||||
Type[] constructorParams = null;
|
||||
MemberInfo constructorMemberInfo = null;
|
||||
object[] constructorValues = null;
|
||||
|
||||
if (string.IsNullOrEmpty(validator.OptionalValidationGroup))
|
||||
{
|
||||
constructorParams = new Type[] { typeof(string) };
|
||||
constructorMemberInfo = typeof(RequiredFieldValidator).GetConstructor(constructorParams);
|
||||
constructorValues = new object[] { validator.ErrorMessage};
|
||||
}
|
||||
else
|
||||
{
|
||||
constructorParams = new Type[] { typeof(string), typeof(string) };
|
||||
constructorMemberInfo = typeof(RequiredFieldValidator).GetConstructor(constructorParams);
|
||||
constructorValues = new object[] { validator.ErrorMessage, validator.OptionalValidationGroup };
|
||||
}
|
||||
|
||||
|
||||
if (constructorMemberInfo != null)
|
||||
{
|
||||
return new InstanceDescriptor(constructorMemberInfo, constructorValues);
|
||||
}
|
||||
}
|
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,102 @@
|
||||
#if FRAMEWORK20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Validator;
|
||||
|
||||
namespace DevComponents.DotNetBar.Design
|
||||
{
|
||||
internal class SuperValidatorDesigner : ComponentDesigner
|
||||
{
|
||||
#region Internal Implementation
|
||||
public override void Initialize(IComponent component)
|
||||
{
|
||||
base.Initialize(component);
|
||||
if (!component.Site.DesignMode)
|
||||
return;
|
||||
|
||||
#if !TRIAL
|
||||
IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
dh.LoadComplete += new EventHandler(dh_LoadComplete);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FRAMEWORK20
|
||||
public override void InitializeNewComponent(IDictionary defaultValues)
|
||||
{
|
||||
base.InitializeNewComponent(defaultValues);
|
||||
SetDesignTimeDefaults();
|
||||
}
|
||||
#else
|
||||
public override void OnSetComponentDefaults()
|
||||
{
|
||||
base.OnSetComponentDefaults();
|
||||
SetDesignTimeDefaults();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void SetDesignTimeDefaults()
|
||||
{
|
||||
SuperValidator sv = this.Component as SuperValidator;
|
||||
if (sv == null)
|
||||
return;
|
||||
|
||||
#if !TRIAL
|
||||
string key = GetLicenseKey();
|
||||
sv.LicenseKey = key;
|
||||
#endif
|
||||
// Create and assign error provider
|
||||
IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
{
|
||||
ErrorProvider provider = dh.CreateComponent(typeof(ErrorProvider)) as ErrorProvider;
|
||||
if (provider == null) return;
|
||||
Highlighter highlighter = dh.CreateComponent(typeof(Highlighter)) as Highlighter;
|
||||
if (highlighter == null) return;
|
||||
if (highlighter.ContainerControl == null)
|
||||
highlighter.ContainerControl = dh.RootComponent as Control;
|
||||
|
||||
TypeDescriptor.GetProperties(sv)["Highlighter"].SetValue(sv, highlighter);
|
||||
TypeDescriptor.GetProperties(sv)["ErrorProvider"].SetValue(sv, provider);
|
||||
provider.Icon = Helpers.LoadIcon("Validator.SuperValidator.ico");
|
||||
sv.ContainerControl = dh.RootComponent as Control;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Licensing
|
||||
#if !TRIAL
|
||||
private string GetLicenseKey()
|
||||
{
|
||||
string key = "";
|
||||
Microsoft.Win32.RegistryKey regkey = Microsoft.Win32.Registry.LocalMachine;
|
||||
regkey = regkey.OpenSubKey("Software\\DevComponents\\Licenses", false);
|
||||
if (regkey != null)
|
||||
{
|
||||
object keyValue = regkey.GetValue("DevComponents.DotNetBar.DotNetBarManager2");
|
||||
if (keyValue != null)
|
||||
key = keyValue.ToString();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
private void dh_LoadComplete(object sender, EventArgs e)
|
||||
{
|
||||
IDesignerHost dh = this.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
dh.LoadComplete -= new EventHandler(dh_LoadComplete);
|
||||
|
||||
string key = GetLicenseKey();
|
||||
SuperValidator sv = this.Component as SuperValidator;
|
||||
if (key != "" && sv != null && sv.LicenseKey == "" && sv.LicenseKey != key)
|
||||
TypeDescriptor.GetProperties(sv)["LicenseKey"].SetValue(sv, key);
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,93 @@
|
||||
#if FRAMEWORK20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing.Design;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms.Design;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Validator;
|
||||
|
||||
namespace DevComponents.DotNetBar.Design
|
||||
{
|
||||
public class ValidationExpressionEditor : UITypeEditor
|
||||
{
|
||||
#region Implementation
|
||||
private IWindowsFormsEditorService _EditorService = null;
|
||||
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||
{
|
||||
if (context != null
|
||||
&& context.Instance != null
|
||||
&& provider != null)
|
||||
{
|
||||
ValidatorBase es = value as ValidatorBase;
|
||||
|
||||
_EditorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
|
||||
|
||||
if (_EditorService != null)
|
||||
{
|
||||
ListBox list = new ListBox();
|
||||
list.Items.Add("At least 5 characters");
|
||||
list.Items.Add("Phone Number");
|
||||
list.Items.Add("E-mail Address");
|
||||
list.Items.Add("ZIP Code");
|
||||
list.Items.Add("Social Security Number");
|
||||
list.Items.Add("URL");
|
||||
list.Items.Add("First, Last Name");
|
||||
list.SelectedIndexChanged += new EventHandler(ValidatorListSelectedIndexChanged);
|
||||
|
||||
_EditorService.DropDownControl(list);
|
||||
|
||||
if (list.SelectedIndex < 0) return es;
|
||||
|
||||
string regExp = "";
|
||||
if (list.SelectedIndex == 1) // Phone Number
|
||||
regExp = @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$";
|
||||
else if (list.SelectedIndex == 2) // Email Address
|
||||
regExp = @"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
|
||||
else if (list.SelectedIndex == 3) // ZIP Code
|
||||
regExp = @"^(\d{5}-\d{4}|\d{5}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$";
|
||||
else if (list.SelectedIndex == 4) // SSN
|
||||
regExp = @"^\d{3}-\d{2}-\d{4}$";
|
||||
else if (list.SelectedIndex == 5) // URL
|
||||
regExp = @"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$";
|
||||
else if (list.SelectedIndex == 6) // First Name, Last Name
|
||||
regExp = @"^[a-zA-Z''-'\s]{1,40}$";
|
||||
else // At least 5 characters
|
||||
regExp = @"\S{5,5}";
|
||||
|
||||
return regExp;
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private void ValidatorListSelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (_EditorService != null)
|
||||
_EditorService.CloseDropDown();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the editor style used by the EditValue method.
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
|
||||
/// <returns>A UITypeEditorEditStyle value that indicates the style of editor used by EditValue. If the UITypeEditor does not support this method, then GetEditStyle will return None.
|
||||
/// </returns>
|
||||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
||||
{
|
||||
if (context != null && context.Instance != null)
|
||||
{
|
||||
return UITypeEditorEditStyle.DropDown;
|
||||
}
|
||||
return base.GetEditStyle(context);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,100 @@
|
||||
#if FRAMEWORK20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing.Design;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms.Design;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Windows.Forms;
|
||||
using DevComponents.DotNetBar.Validator;
|
||||
|
||||
namespace DevComponents.DotNetBar.Design
|
||||
{
|
||||
public class ValidatorEditor : UITypeEditor
|
||||
{
|
||||
#region Implementation
|
||||
private IWindowsFormsEditorService _EditorService = null;
|
||||
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||
{
|
||||
if (context != null
|
||||
&& context.Instance != null
|
||||
&& provider != null)
|
||||
{
|
||||
ValidatorBase es = value as ValidatorBase;
|
||||
|
||||
_EditorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
|
||||
|
||||
if (_EditorService != null)
|
||||
{
|
||||
ListBox list = new ListBox();
|
||||
list.Items.Add("(none)");
|
||||
list.Items.Add("Required Field Validator");
|
||||
list.Items.Add("Regular Expression Validator");
|
||||
list.Items.Add("Compare Fields Validator");
|
||||
list.Items.Add("Range Validator");
|
||||
list.Items.Add("Custom Code Validator");
|
||||
list.SelectedIndexChanged += new EventHandler(ValidatorListSelectedIndexChanged);
|
||||
|
||||
_EditorService.DropDownControl(list);
|
||||
|
||||
int listSelectedIndex = list.SelectedIndex;
|
||||
if (listSelectedIndex > 0)
|
||||
{
|
||||
listSelectedIndex--;
|
||||
Type validatorType = null;
|
||||
if (listSelectedIndex == 1)
|
||||
validatorType = typeof(RegularExpressionValidator);
|
||||
else if (listSelectedIndex == 2)
|
||||
validatorType = typeof(CompareValidator);
|
||||
else if (listSelectedIndex == 3)
|
||||
validatorType = typeof(RangeValidator);
|
||||
else if (listSelectedIndex == 4)
|
||||
validatorType = typeof(CustomValidator);
|
||||
else
|
||||
validatorType = typeof(RequiredFieldValidator);
|
||||
|
||||
IDesignerHost dh = provider.GetService(typeof(IDesignerHost)) as IDesignerHost;
|
||||
if (dh != null)
|
||||
{
|
||||
ValidatorBase val = dh.CreateComponent(validatorType) as ValidatorBase;
|
||||
val.HighlightColor = eHighlightColor.Red;
|
||||
val.ErrorMessage = "Your error message here.";
|
||||
return val;
|
||||
}
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
return es;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ValidatorListSelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (_EditorService != null)
|
||||
_EditorService.CloseDropDown();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the editor style used by the EditValue method.
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
|
||||
/// <returns>A UITypeEditorEditStyle value that indicates the style of editor used by EditValue. If the UITypeEditor does not support this method, then GetEditStyle will return None.
|
||||
/// </returns>
|
||||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
||||
{
|
||||
if (context != null && context.Instance != null)
|
||||
{
|
||||
return UITypeEditorEditStyle.DropDown;
|
||||
}
|
||||
return base.GetEditStyle(context);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user