コード例 #1
0
        /// <summary>
        /// Initializes the NumberColumn with default values
        /// </summary>
        private void Init()
        {
            this.Format = "G";

            this.numberColumnType = NumberColumnType.DECIMAL;
            this.maximum          = (decimal)100;
            this.minimum          = (decimal)0;
            this.increment        = (decimal)1;

            this.showUpDownButtons = false;
            this.upDownAlignment   = LeftRightAlignment.Right;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the NumberCellEditor class with default settings
        /// </summary>
        public I3NumberCellEditor()
        {
            TextBox textbox = new TextBox();

            textbox.AutoSize    = false;
            textbox.BorderStyle = BorderStyle.None;
            this.Control        = textbox;

            this.numberColumnType = NumberColumnType.DECIMAL;
            this.currentValue     = new decimal(0);
            this.increment        = new decimal(1);
            this.minimum          = new decimal(0);
            this.maximum          = new decimal(100);
            this.format           = "G";

            this.wheelDelta         = 0;
            this.interceptArrowKeys = true;
            this.userEdit           = false;
            this.changingText       = false;
            this.buttonBounds       = Rectangle.Empty;
            this.buttonID           = 0;
            this.interval           = TimerInterval;
        }
コード例 #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            object result = base.ConvertFrom(context, culture, value);

            if (result is double)
            {
                if (context.Instance == null || context.Instance.GetType() != context.PropertyDescriptor.ComponentType)
                {
                    throw new Exception("the NumberConvert is only work for single object");
                }
                object       source   = context.Instance;
                PropertyInfo property = context.PropertyDescriptor.ComponentType.GetProperty(context.PropertyDescriptor.Name);
                if (property != null)
                {
                    object propertyValue = property.GetValue(source, null);
                    if (propertyValue != null)
                    {
                        Type             propertyType     = propertyValue.GetType();
                        NumberColumnType numberColumnType = NumberColumnTypeHelper.GetNumberColumnType(propertyType);
                        switch (numberColumnType)
                        {
                        case NumberColumnType.SBYTE:
                            return(Convert.ToSByte((double)result));

                        case NumberColumnType.BYTE:
                            return(Convert.ToByte((double)result));

                        case NumberColumnType.SHORT:
                            return(Convert.ToInt16((double)result));

                        case NumberColumnType.USHORT:
                            return(Convert.ToUInt16((double)result));

                        case NumberColumnType.INT:
                            return(Convert.ToInt32((double)result));

                        case NumberColumnType.UINT:
                            return(Convert.ToUInt32((double)result));

                        case NumberColumnType.LONG:
                            return(Convert.ToInt64((double)result));

                        case NumberColumnType.ULONG:
                            return(Convert.ToUInt64((double)result));

                        case NumberColumnType.FLOAT:
                            return(Convert.ToSingle((double)result));

                        case NumberColumnType.DOUBLE:
                            return((double)result);

                        case NumberColumnType.DECIMAL:
                            return(Convert.ToDecimal((double)result));

                        default:
                            return(Convert.ToDecimal((double)result));
                        }
                    }
                }
            }
            return(result);
        }