Showing posts with label coder. Show all posts
Showing posts with label coder. Show all posts

Thursday, March 17, 2011

C# TextBox input values with decimal places

This code shows how to make a textbox that let's user input values with decimal places.

1. Create a textbox and name in "textBox".
2. Create a keypress event.
3. copy and paste the code below. ( the code lets the user input numbers up to two decimal places ).

// check if key pressed is numeric, backspace or decimal character " . "


if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+") 
&& e.KeyChar != (char)Keys.Back && e.KeyChar != '.')
   {        e.Handled = true;    } if (e.KeyChar == '.')    {        if (textBox.Text.Contains('.'))        {            e.Handled = true;           return;        }                   }
 if (System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))   {     if (textBox.Text.Contains('.'))      {             // - 3 is for the decimal places. 
//You may make it 4 or 5 depends on your application             if (textBox.Text.IndexOf('.') == textBox.Text.Length - 3)             e.Handled = true;        }    }

Monday, February 1, 2010

Different Types of Programmers

I copied this from someone else but forgot where...

The Elite / MVP (Most Valuable Programmer) – They are the best. The last line of defense when the critical-dead line of a project must be done. They are the untouchable. If you are 10 on the group, he done almost 70% of the job. He is much better than your team leader, best than the seniors. The right man for the job. Even though in personal life, he got the style.

The Copy-Paste Programmer – These individual proves that the google serves us well especially on our careers. He can give you solution in less than a minute with a variety of more than 20 selections. We called it “The Search Engine Professionals.” They are the experts in browsing the web. Copy the code, paste the code, edit the code, and compile the code.

Related Posts with Thumbnails