コード例 #1
0
        internal void SetData <T>(NumericUpDownData <T> numericUpDownControl) where T : struct, IFormattable, IComparable <T>
        {
            Control control;
            Binding binding = new Binding("Value");

            binding.Source = numericUpDownControl;
            if (typeof(T) == typeof(int))
            {
                var numeric = new IntegerUpDown();
                numeric.Minimum = Convert.ToInt32(numericUpDownControl._min);
                numeric.Maximum = Convert.ToInt32(numericUpDownControl._max);
                numeric.UpdateValueOnEnterKey = true;
                numeric.FormatString          = numericUpDownControl.FormatString;
                numeric.SetBinding(IntegerUpDown.ValueProperty, binding);

                control = numeric;
            }
            else if (typeof(T) == typeof(decimal))
            {
                var numeric = new DecimalUpDown();
                numeric.Minimum               = Convert.ToDecimal(numericUpDownControl._min);
                numeric.Maximum               = Convert.ToDecimal(numericUpDownControl._max);
                numeric.Increment             = (numeric.Maximum - numeric.Minimum) / 100;
                numeric.UpdateValueOnEnterKey = true;
                numeric.FormatString          = numericUpDownControl.FormatString;
                numeric.SetBinding(DecimalUpDown.ValueProperty, binding);
                control = numeric;
            }
            else if (typeof(T) == typeof(double))
            {
                var numeric = new DoubleUpDown();
                numeric.Minimum = Convert.ToDouble(numericUpDownControl._min);
                numeric.Maximum = Convert.ToDouble(numericUpDownControl._max);
                numeric.UpdateValueOnEnterKey = true;
                numeric.SetBinding(DoubleUpDown.ValueProperty, binding);
                numeric.FormatString = numericUpDownControl.FormatString;
                control = numeric;
            }
            else
            {
                throw new Exception($"Inavlid type, Expected int,double or decimal received {typeof(T)}");
            }
            //control.Width = 200;
            //control.Height = 24;
            control.Name       = "Numeric";
            control.Background = Brushes.LightGoldenrodYellow;
            control.KeyDown   += Control_KeyDown;

            this.PlaceHolder.Children.Add(control);
        }
コード例 #2
0
        internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            base.MouseRightClick(sender, customComponent, e, ref result);
            if (result.HasFlag(GHMouseEventResult.Handled))
            {
                return;
            }
            decimal d = Convert.ToDecimal(CurrentValue);
            NumericUpDownData <decimal> numeric = new NumericUpDownData <decimal>(d, Convert.ToDecimal(_min), Convert.ToDecimal(_max), FormatString);

            if (numeric.GetInput(PointToScreen(sender, Pos), out decimal val))
            {
                CurrentValue = (float)val;
                result       = result | GHMouseEventResult.UpdateSolution | GHMouseEventResult.Handled;
            }
            else
            {
                result = result | GHMouseEventResult.Handled;
            }
            showLabel = true;
        }
コード例 #3
0
        internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            base.MouseRightClick(sender, customComponent, e, ref result);
            if (result.HasFlag(GHMouseEventResult.Handled))
            {
                return;
            }
            int d = (int)CurrentValue;
            NumericUpDownData <int> numeric = new NumericUpDownData <int>(d, (int)_min, (int)_max, FormatString);

            if (numeric.GetInput(PointToScreen(sender, Pos), out int val))
            {
                CurrentValue = val;
                result       = result | GHMouseEventResult.UpdateSolution | GHMouseEventResult.Handled;
            }
            else
            {
                result = result | GHMouseEventResult.Handled;
            }
            showLabel = true;
        }
コード例 #4
0
        internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            base.MouseRightClick(sender, customComponent, e, ref result);
            if (result.HasFlag(GHMouseEventResult.Handled))
            {
                return;
            }
            double d = (double)CurrentValue;
            NumericUpDownData <double> numeric = new NumericUpDownData <double>(d, _min, _max, FormatString);

            //float s = GH_FontServer.MeasureString("A", SmallFont).Height * sender.Viewport.Zoom / 20;
            if (numeric.GetInput(PointToScreen(sender, Pos), out double val))
            {
                CurrentValue = val;
                result       = result | GHMouseEventResult.UpdateSolution | GHMouseEventResult.Handled;
            }
            else
            {
                result = result | GHMouseEventResult.Handled;
            }
            showLabel = true;
        }