ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Create a Numeric Text Box
    IT Story/C# & WPF 2019. 12. 3. 11:45
    반응형

    A TextBox control is used to display, or accept as input, a single line of text. It can contain only unformatted text in its Text property. In many situations you need to enter only numeric values in the Textbox. Here you can see some useful techniques that accept only numbers in the textbox.

    You can use Regular Expression to validate a Textbox to enter number only.

     

    C# Source Code

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "  ^ [0-9]"))
                {
                    textBox1.Text = "";
                }
            }
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
                {
                    e.Handled = true;
                }
            }
        }
    }

    How to Autocomplete TextBox

    The properties like AutoCompleteCustomSource, AutoCompleteMode and AutoCompleteSource to perform a TextBox that automatically completes user input strings by comparing the prefix letters being entered to the prefixes of all strings in a data source. More about.... Autocomplete TextBox

    반응형

    'IT Story > C# & WPF' 카테고리의 다른 글

    A Short History of Sorting in C#  (0) 2019.12.05
    How to use C# ArrayList Class  (0) 2019.12.05
    C# String to Number Conversion  (0) 2019.12.03
    Convert Byte Array To String In C#  (0) 2019.12.03
    TASK.RUN VS ASYNC AWAIT  (0) 2019.11.27

    댓글

Designed by Tistory.