textbox property

Asked By madhu radha
07-Nov-09 06:51 AM
Earn up to 0 extra points for answering this tough question.

hi all,

  i want a textbox for cost purpose which should accept  dot before last two digits  

  re

Web Star replied to madhu radha
07-Nov-09 08:47 AM

u can use this

Listing 1 - Overriding the KeyPress event

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (e.KeyChar >= '0' && e.KeyChar <= '9')
            {
               
// move all digits over to the left
                Shift(); 
                // make sure there is a prompt to replace
                int index = this.Text.LastIndexOf(PromptChar);
                if (index >= 0)
                {
                   
// insert the character typed into the last prompt character of the Text string
                    this.Text = this.Text.Substring(0, index) + e.KeyChar + this.Text.Substring(index);
                }
           }
            base.OnKeyPress(e);
        }

http://www.dotnetheaven.com/Uploadfile/mgold/MaskedCurrencyTextBox02252006005553AM/MaskedCurrencyTextBox.aspx

http://www.c-sharpcorner.com/UploadFile/jibinpan/MaskedTextBoxControl11302005051817AM/MaskedTextBoxControl.aspx

  Use MaskedTextBox

mv ark replied to madhu radha
07-Nov-09 08:57 AM
Use the MaskedTextBox Control - http://msdn.microsoft.com/en-us/library/ka7h9fze.aspx

  re

Web Star replied to madhu radha
07-Nov-09 09:56 AM

if u are using latest version of vs.net 3.0 then there are one mask property of textbox , where u can set for input format as

MaskedTextBox.Mask = "####.##"

source is here http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx

  RegularExpressionValidator
F Cali replied to madhu radha
07-Nov-09 11:43 PM

You can use the RegularExpressionValidator for your TextBox.  Here's a link to know more about the Regular Expression Validator:

http://msdn.microsoft.com/en-us/library/ms998267.aspx

From that link, you can use this as your validator: ^\d+(\.\d\d)?$

Regards,
SQL Server Helper

Create New Account