コード例 #1
0
        private void TextBoxTextChangingHandler(TextBox sender, TextBoxTextChangingEventArgs args)
        {
            var text = sender.Text;

            text = text.StripNonDigit();
            long value;

            if (String.IsNullOrWhiteSpace(text))
            {
                sender.Text = "";
                return;
            }
            else
            {
                value = long.Parse(text);
            }

            if (value > MaxNumber)
            {
                value = MaxNumber;
            }
            else if (value < MinNumber)
            {
                value = MinNumber;
            }

            Number      = (int)value;
            sender.Text = value.ToString();
            NumberChanged?.Invoke(sender, null);
        }
コード例 #2
0
        internal void MyNumberChanged()
        {
            textBox.Text    = Number.ToString(FormatString);
            scrollBar.Value = Invert(Number);

            NumberChanged?.Invoke(this, null);
        }
コード例 #3
0
        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if ((sender == textBoxAreaCode) && (textBoxAreaCode.Text.Length == 3))
            {
                textBoxPrefix.Focus();
            }
            if ((sender == textBoxPrefix) && (textBoxPrefix.Text.Length == 3))
            {
                textBoxNumber.Focus();
            }

            if ((textBoxAreaCode.Text.Length == 3) && (textBoxPrefix.Text.Length == 3) &&
                (textBoxNumber.Text.Length == 4))
            {
                try
                {
                    int areaCode = Convert.ToInt32(textBoxAreaCode.Text);
                    int prefix   = Convert.ToInt32(textBoxPrefix.Text);
                    int number   = Convert.ToInt32(textBoxNumber.Text);
                    if (NumberChanged != null)
                    {
                        NumberChanged.Invoke(this, new EventArgs());
                    }
                    return;
                }
                catch
                {
                }
            }
            if (ContentsInvalid != null)
            {
                ContentsInvalid.Invoke(this, new EventArgs());
            }
        }
コード例 #4
0
 public void NotifyNumberChanged(int value)
 {
     if (!value.Equals(_Value))
     {
         _Value = value;
         NumberChanged?.Invoke(this, EventArgs.Empty);
     }
 }
コード例 #5
0
ファイル: NumberChangedTest.cs プロジェクト: sanjaybxl/inform
        public void CaseNumberChanged()
        {
            var           id     = Guid.NewGuid();
            NumberChanged numObj = new NumberChanged(id, ModuleType.Incident, "data");

            numObj.NumberId.Should().Be(id);
            numObj.ModuleType.Should().Be(ModuleType.Incident);
            numObj.NewValue.Should().Be("data");
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: zhonghuasheng/.NET
        public List <string> DoSomething()
        {
            List <string> strList = new List <string>();

            if (NumberChanged == null)
            {
                return(strList);
            }
            Delegate[] delArray = NumberChanged.GetInvocationList();
            foreach (Delegate del in delArray)
            {
                DemoEventHandler method = (DemoEventHandler)del;//强制向下转换
                strList.Add(method(100));
            }
            return(strList);
        }
コード例 #7
0
        public event DemoEventHandler NumberChanged; // 声明一个事件
        public List <string> DoSomething()
        {
            // 做某些其他的事
            List <string> strList = new List <string>();

            if (NumberChanged == null)
            {
                return(strList);
            }
            // 获得委托数组
            Delegate[] delArray = NumberChanged.GetInvocationList();
            foreach (Delegate del in delArray)
            {
                // 进行一个向下转换
                DemoEventHandler method = (DemoEventHandler)del;
                strList.Add(method(100)); // 调用方法并获取返回值
            }
            return(strList);
        }
コード例 #8
0
 public void DoSomething()
 {
     if (NumberChanged != null)
     {
         Delegate[] dels = NumberChanged.GetInvocationList();
         foreach (Delegate del in dels)
         {
             NumberChangedEventHandler handler = del as NumberChangedEventHandler;
             try
             {
                 handler(serverName, count);
             }
             catch (Exception ex)
             {
                 Delegate.Remove(NumberChanged, del);
             }
         }
     }
 }
コード例 #9
0
 public void DoSomething()
 {
     count++;
     if (NumberChanged != null)
     {
         Delegate[] delArray = NumberChanged.GetInvocationList();
         foreach (Delegate del in delArray)
         {
             NumberChangedEventHandler method;//=(NumberChangedEventHandler)
             try
             {
                 method(serverName, count);
             }
             catch (Exception)
             {
                 Delegate.Remove(NumberChanged, del);
             }
         }
     }
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: imtudou/dotnetcore.Sample
        public event NumberChangedEventHandler NumberChanged; //

        public List <string> PublishNumber(int count)
        {
            List <string> list = new List <string>();

            if (NumberChanged == null)
            {
                return(list);
            }

            // 获得委托数组
            Delegate[] delegateArray = NumberChanged.GetInvocationList();

            foreach (var item in delegateArray)
            {
                // 进行一个向下转换
                NumberChangedEventHandler method = (NumberChangedEventHandler)item;
                if (NumberChanged == null)
                {
                    return(list);
                }
                list.Add(method(100));       // 调用方法并获取返回值
            }
            return(list);
        }
コード例 #11
0
 public void OnNumberboxChanged(int Id, double Value)
 => NumberChanged?.Invoke(Id, Value);
コード例 #12
0
 public void OnNumberboxChanged(int Id, double Value)
 {
     NumberChanged?.Invoke(Id, Value);
     DataChanged?.Invoke();
 }
コード例 #13
0
 /// <summary>
 /// Benachrichtigt die registrierten Beobachter, dass eine neue Zahl generiert wurde.
 /// </summary>
 /// <param name="number">Die generierte Zahl.</param>
 public void NotifyObservers(int number)
 {
     NumberChanged.Invoke(number);
 }
コード例 #14
0
 private void Apply(NumberChanged e)
 {
     Number = e.Number;
 }
コード例 #15
0
 public void DetermineNumber()
 {
     _elapsedTime   = 0;
     _currentNumber = Random.Range(_minValue, _maxValue);
     NumberChanged?.Invoke(_currentNumber);
 }
コード例 #16
0
        private async Task HasLostFocus()
        {
            var data = await JsModule.InvokeAsync <string>("GetNumericTextBoxValue", new string[] { "#" + Id });

            var cleaned = string.Join("",
                                      data.Replace("(", "-").Where(x => char.IsDigit(x) ||
                                                                   x == '-' ||
                                                                   x.ToString() == DecimalSeparator).ToArray());
            var parsed = decimal.TryParse(cleaned, NumberStyles.Any, Culture.NumberFormat, out var valueAsDecimal);

            if (!parsed)
            {
                if (string.IsNullOrEmpty(Format))
                {
                    VisibleValue = "";
                }
                else
                {
                    VisibleValue = 0.ToString(Format);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Format))
                {
                    VisibleValue = cleaned;
                }
                else
                {
                    VisibleValue = valueAsDecimal.ToString(Format);
                }
            }

            // Negative monetary values a represented with parenthesis
            cleaned = string.Join("",
                                  VisibleValue.Replace("(", "-")
                                  .Where(x => char.IsDigit(x) ||
                                         x == '-' ||
                                         x.ToString() == DecimalSeparator).ToArray());

            parsed = decimal.TryParse(cleaned, NumberStyles.Any, Culture.NumberFormat, out var roundedValue);

            if (parsed)
            {
                Value = (TItem)Convert.ChangeType(roundedValue, typeof(TItem));
            }
            else
            {
                Value = (TItem)Convert.ChangeType(valueAsDecimal, typeof(TItem));
            }

            // Do not remove. Problems in browser events and Blazor changes the value of the Value property
            var value = Value;

            await SetVisibleValue(Value);

            Value = value;
            await ValueChanged.InvokeAsync(Value);

            if (!PreviousValue.Equals(Value))
            {
                if (!string.IsNullOrEmpty(FieldIdentifier.FieldName))
                {
                    EditContext.NotifyFieldChanged(FieldIdentifier);
                }
                await NumberChanged.InvokeAsync(Value);
            }

            AdditionalStyles = AlignToRight;

            if (OnBlur != null)
            {
                await OnBlur.Invoke();
            }
        }