public static void SetupCallbacks(Control control, MyTextBox textBox) { MouseEventHandler MouseDown = (a, args) => textBox.MouseDown(args); MouseEventHandler MouseUp = (a, args) => textBox.MouseUp(args); MouseEventHandler MouseMove = (a, args) => textBox.MouseMove(args); MouseEventHandler MouseClick = (a, args) => textBox.MouseClick(args); KeyPressEventHandler KeyPress = (a, args) => textBox.KeyPress(args); KeyEventHandler KeyDown = (a, args) => textBox.KeyDown(args); PaintEventHandler Paint = (a, args) => textBox.Paint(args.Graphics); EventHandler GotFocus = (a, args) => textBox.GotFocus(); EventHandler LostFocus = (a, args) => textBox.LostFocus(); control.MouseDown += MouseDown; control.MouseUp += MouseUp; control.MouseMove += MouseMove; control.MouseClick += MouseClick; control.KeyPress += KeyPress; control.KeyDown += KeyDown; control.Paint += Paint; control.GotFocus += GotFocus; control.LostFocus += LostFocus; textBox.PushDisposeActions(() => { control.MouseDown -= MouseDown; control.MouseUp -= MouseUp; control.MouseMove -= MouseMove; control.MouseClick -= MouseClick; control.KeyPress -= KeyPress; control.KeyDown -= KeyDown; control.Paint -= Paint; control.GotFocus -= GotFocus; control.LostFocus -= LostFocus; }); }
public MyNumericUpDown(Control control, Func <RectangleF> area, bool decimalAllowed, Font font) { m_area = area; m_buttonUpArea = () => { var a = area(); return(new RectangleF(a.Right - BUTTON_WIDTH, a.Top, BUTTON_WIDTH, a.Height / 2)); }; m_buttonDownArea = () => { var a = area(); return(new RectangleF(a.Right - BUTTON_WIDTH, a.Top + a.Height / 2, BUTTON_WIDTH, a.Height / 2)); }; Func <RectangleF> m_textBoxArea = () => { var a = area(); return(RectangleF.FromLTRB(a.Left, a.Top, a.Right - BUTTON_WIDTH, a.Bottom)); }; m_textBox = new MyTextBox(control, m_textBoxArea, decimalAllowed ? MyTextBox.InputFormEnum.Decimal : MyTextBox.InputFormEnum.Integer, null, x => MyTextBox.ComboBoxBorderDaniel, 4, font); m_textBox.RequestedAreaChanged += () => { RequestedArea = new SizeF(Area.Width, m_textBox.RequestedArea.Height); }; m_textBox.TextChanged += (string oldText) => { if (m_textBox.Text.Length == 0 || m_textBox.Text == "-") { m_value = 0; } else { if (typeof(T) == typeof(decimal)) { if (!decimal.TryParse(m_textBox.Text, out m_value)) { m_textBox.Text = oldText; } } if (typeof(T) == typeof(int)) { if (!int.TryParse(m_textBox.Text, out int value)) { m_textBox.Text = oldText; } else { m_value = value; } } } }; m_mouseUpTimer.Tick += (a, b) => { if (Value <= decimal.MaxValue - Increment) { Value += Increment; } m_mouseUpTimer.Interval = (int)(m_mouseUpTimer.Interval * 0.95).Clamp(1, 10000); }; m_mouseDownTimer.Tick += (a, b) => { Value -= Increment; m_mouseDownTimer.Interval = (int)(m_mouseDownTimer.Interval * 0.95).Clamp(1, 10000);; }; Minimum = () => 0; Maximum = () => 0; Value = 0; }
public SimpleTextBoxBorderDrawer(MyTextBox textBox) { m_textBox = textBox; }