public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object Value)
        {
            ValueValidateStyle style = Value as ValueValidateStyle;

            if (style == null)
            {
                style = new ValueValidateStyle();
            }
            else
            {
                style = style.Clone();
            }
            using (dlgValueValidateStyleEditor dlg = new dlgValueValidateStyleEditor())
            {
                dlg.ValidateStyle = style;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    return(dlg.ValidateStyle);
                }
            }
            return(Value);
        }
        private void dlgValueValidateStyleEditor_Load(object sender, EventArgs e)
        {
            if (myValidateStyle == null)
            {
                myValidateStyle = new ValueValidateStyle();
            }
            this.txtValueName.Text     = myValidateStyle.ValueName;
            this.txtCustomMessage.Text = myValidateStyle.CustomMessage;
            this.chkRequire.Checked    = myValidateStyle.Required;
            rdoDate.Checked            = false;
            rdoNumeric.Checked         = false;
            rdoText.Checked            = false;
            rdoTime.Checked            = false;
            if (myValidateStyle.ValueType == ValueTypeStyle.Text)
            {
                rdoText.Checked      = true;
                chkMaxLength.Checked = myValidateStyle.CheckMaxValue;
                chkMinLength.Checked = myValidateStyle.CheckMinValue;
                txtMaxLength.Value   = myValidateStyle.MaxLength;
                txtMinLength.Value   = myValidateStyle.MinLength;
            }
            else if (myValidateStyle.ValueType == ValueTypeStyle.Numeric ||
                     myValidateStyle.ValueType == ValueTypeStyle.Integer)
            {
                rdoNumeric.Checked  = true;
                chkInteger.Checked  = myValidateStyle.ValueType == ValueTypeStyle.Integer;
                chkMaxValue.Checked = myValidateStyle.CheckMaxValue;
                if (double.IsNaN(myValidateStyle.MaxValue) == false)
                {
                    txtMaxValue.Text = myValidateStyle.MaxValue.ToString();
                }
                chkMinValue.Checked = myValidateStyle.CheckMinValue;
                if (double.IsNaN(myValidateStyle.MinValue) == false)
                {
                    txtMinValue.Text = myValidateStyle.MinValue.ToString();
                }
            }
            else if (myValidateStyle.ValueType == ValueTypeStyle.Date ||
                     myValidateStyle.ValueType == ValueTypeStyle.DateTime)
            {
                rdoDate.Checked        = true;
                dtpMaxDate.Value       = myValidateStyle.DateTimeMaxValue;
                dtpMaxTime.Value       = myValidateStyle.DateTimeMaxValue;
                chkMaxDateTime.Checked = myValidateStyle.CheckMaxValue;

                dtpMinDate.Value       = myValidateStyle.DateTimeMinValue;
                dtpMinTime.Value       = myValidateStyle.DateTimeMinValue;
                chkMinDateTime.Checked = myValidateStyle.CheckMinValue;
            }
            else if (myValidateStyle.ValueType == ValueTypeStyle.Time)
            {
                rdoTime.Checked = true;

                dtpMaxTime2.Value  = new DateTime(1900, 1, 1).Add(myValidateStyle.DateTimeMaxValue.TimeOfDay);
                chkMaxTime.Checked = !myValidateStyle.CheckMaxValue;

                chkMinTime.Checked = !myValidateStyle.CheckMinValue;
                dtpMinTime2.Value  = new DateTime(1900, 1, 1).Add(myValidateStyle.DateTimeMinValue.TimeOfDay);
            }
            SetControlState(this.rdoText, this.grbTextStyle);
            SetControlState(this.rdoDate, this.grpDateTimeStyle);
            SetControlState(this.rdoTime, this.grpTimeStyle);
            SetControlState(this.rdoNumeric, this.grbNumericStyle);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <returns>复制品</returns>
        object System.ICloneable.Clone()
        {
            ValueValidateStyle style = (ValueValidateStyle)this.MemberwiseClone();

            return(style);
        }