⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numericbox.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -