1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace UAS_MES_NEW.CustomControl.TextBoxWithIcon
- {
- public partial class TextBoxNumOnly : TextBox
- {
- public TextBoxNumOnly()
- {
- InitializeComponent();
- this.KeyPress += OnKeyPress;
- this.Enter += OnEnter;
- this.Leave += OnLeave;
- }
-
-
-
- public override string Text
- {
- get
- {
-
- if (base.Text == "")
- {
- return "0";
- }
- return base.Text;
- }
- set
- {
- base.Text = value;
- }
- }
- private void OnKeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != '\b')
- {
- if ((e.KeyChar < '0') || (e.KeyChar > '9'))
- {
- e.Handled = true;
- }
- }
- }
- private void OnEnter(object sender, EventArgs e)
- {
- BackColor = Color.GreenYellow;
- }
- private void OnLeave(object sender, EventArgs e)
- {
- BackColor = Color.White;
- }
- }
- }
|