numericbox.cs

来自「Fireball.CodeEditor is an source code ed」· CS 代码 · 共 87 行

CS
87
字号
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

using Fireball.Collections.Generic;

namespace Fireball.Windows.Forms
{
    [ToolboxItem(true)]
    public class NumericBox:Control 
    {
        private bool _onError;
        private NumericTextBox _numBox;
        private LightCollection<NumericRange> _ranges;
        private bool _hasComma;
        private bool _hasNumbers;
        private bool _onFlashing;
        private int _flashCount;
        private bool _lastError;
        private int _decimalPlace;
        private decimal _value;
        public bool _allowError;

        private System.Timers.Timer _timer;

        public NumericBox()
        {
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint | 
                ControlStyles.OptimizedDoubleBuffer | 
                ControlStyles.ResizeRedraw | 
                ControlStyles.EnableNotifyMessage|
                ControlStyles.UserPaint
                , true);

            _onError = false;
            _hasComma = false;
            _hasNumbers = false;
            _onFlashing = false;
            _flashCount = 0;
            _value = new decimal();

            _allowError = true;

            _timer = new System.Timers.Timer(25);
            _timer.Elapsed+=new System.Timers.ElapsedEventHandler(_timer_Elapsed);

            _ranges = new  LightCollection<NumericRange>();

            _numBox = new NumericTextBox(this);
            _numBox.BorderStyle = BorderStyle.None;
            _numBox.Multiline = false;

            _numBox.TextChanged += new EventHandler(_textBox_TextChanged);
            _numBox.KeyPress += new KeyPressEventHandler(_textBox_KeyPress);

            this.Height = _numBox.Height + 4;
            this.Width = _numBox.Width + 2;

            _numBox.Location = new Point(1, 1);

            this.Controls.Add(_numBox);
        }

        private void _textBox_TextChanged(object sender, EventArgs e)
        {
            if (_numBox.TextLength == 0)
            {
                _hasNumbers = false;
                _hasComma = false;
            }

            _hasComma = _numBox.Text.Contains(",");

            _onError = !Validate();
            this.Invalidate();

            base.OnTextChanged(e);
        }
        private void _textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\b')
            {
                e.Handled = false;
                //TODO: verificare se canceller

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?