zoukankan      html  css  js  c++  java
  • handycontrol中NumericUpDown无法显示自定义错误提示的解决办法

    最新的版本,好像是3.2.

    NumericUpDown控件设置了ErrorStr属性,不管是否带hc名称空间,设置的字符串都不会生效,看了下源码,修改了NumericUpDown.cs中的一句,如下:

    官方源码

    public virtual bool VerifyData()
            {
                OperationResult<bool> result;
    
                if (VerifyFunc != null)
                {
                    result = VerifyFunc.Invoke(_textBox.Text);
                }
                else
                {
                    if (!string.IsNullOrEmpty(_textBox.Text))
                    {
                        if (double.TryParse(_textBox.Text, out var value))
                        {
                            if (value < Minimum || value > Maximum)
                            {
                                result = OperationResult.Failed(Properties.Langs.Lang.OutOfRange);
                            }
                            else
                            {
                                result = OperationResult.Success();
                            }
                        }
                        else
                        {
                            result = OperationResult.Failed(Properties.Langs.Lang.FormatError);
                        }
                    }
                    else if (InfoElement.GetNecessary(this))
                    {
                        result = OperationResult.Failed(Properties.Langs.Lang.IsNecessary);
                    }
                    else
                    {
                        result = OperationResult.Success();
                    }
                }
    
                SetCurrentValue(ErrorStrProperty, result.Message);
                SetCurrentValue(IsErrorProperty, ValueBoxes.BooleanBox(!result.Data));
                return result.Data;
            }

    修改后

    public virtual bool VerifyData()
            {
                OperationResult<bool> result;
    
                if (VerifyFunc != null)
                {
                    result = VerifyFunc.Invoke(_textBox.Text);
                }
                else
                {
                    if (!string.IsNullOrEmpty(_textBox.Text))
                    {
                        if (double.TryParse(_textBox.Text, out var value))
                        {
                            if (value < Minimum || value > Maximum)
                            {
                                result = OperationResult.Failed($"范围{Minimum}-{Maximum}");
                            }
                            else
                            {
                                result = OperationResult.Success();
                            }
                        }
                        else
                        {
                            result = OperationResult.Failed(Properties.Langs.Lang.FormatError);
                        }
                    }
                    else if (InfoElement.GetNecessary(this))
                    {
                        result = OperationResult.Failed(Properties.Langs.Lang.IsNecessary);
                    }
                    else
                    {
                        result = OperationResult.Success();
                    }
                }
    
                SetCurrentValue(ErrorStrProperty, result.Message);
                SetCurrentValue(IsErrorProperty, ValueBoxes.BooleanBox(!result.Data));
                return result.Data;
            }
  • 相关阅读:
    激活OFFICE2010时,提示choice.exe不是有效的win32程序
    Redis 学习之持久化机制、发布订阅、虚拟内存
    Redis 学习之事务处理
    Redis 学习之主从复制
    Redis 学习之常用命令及安全机制
    Redis 学习之数据类型
    Redis 学习之简介及安装
    Tomcat 虚拟主机配置
    mysql学习之权限管理
    mysql学习之主从复制
  • 原文地址:https://www.cnblogs.com/usen521/p/15600171.html
Copyright © 2011-2022 走看看