Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Thousands Separator in C# TextBox ?
Message
 
To
02/04/2007 06:01:36
Handi Rusli
PT. Alam Sumbervita
Jakarta, Indonesia
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01211171
Message ID:
01211306
Views:
18
I'm also a newbie to C# and this is my first custom control but so far it's pretty close to what I wanted to achieve. It lacks an error handling routine and data validation but it'll get you started.
 class NumericTextBox : TextBox 
    {

        private string _InputMask = "###,###,##0.00";
        /// <summary>
        /// Máscara que usará el valor digitado
        /// </summary>
        public string InputMask
        {
            get { return _InputMask; }
            set { _InputMask = value; }
        }

                
        // Declaración de método delegado 
        public delegate void EventHandler(object sender,EventArgs e);

        #region constructor
        public NumericTextBox()
        {
              
            this.Height = 20;
            this.Width = 100;
            this.KeyPress += this.NumericTextBox_KeyPress;  // declara el metodo que funcionará como eventhandler
            this.TextAlign=HorizontalAlignment.Right;
         
        }
        #endregion constructor

        #region Keypress
        // Método que maneja el evento Keypress
        public void NumericTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            char _caracter;
            if (Char.IsDigit(e.KeyChar) | e.KeyChar == '.' )
            {
                _caracter=e.KeyChar;

                // Si el punto ya existe en el texto
                if (_caracter  == '.' & this.Text.Contains(_caracter.ToString()))
                {
                    e.Handled = true;
                }

            }
            else
            { e.Handled = true; }
        }
       #endregion Keypress

        # region Validated
        protected override void  OnValidated(EventArgs e)
        {
            string Valor=this.Text;
            double dValor=Double.Parse(Valor);
            Valor=dValor.ToString(_InputMask);
            this.Text = Valor;
 	        base.OnValidated(e);
        }
        #endregion Validated 

    }
>Hi,
>
>I'm a newbie in C#, from a VFP perspective ... I just want to add thousand separator in Textbox (WinForm App) like in VFP (just put ##,###,### in InputMask property). Can I get this behaviour in C# WinForm ?
>
>Oh, one more question ... What is the best data type for Money ?
>
>Thanks in advance :-)
I'm a mixture of Albert Einstein and Arnold Schwarzenegger. The only trouble is that I got Einstein's body and Schwarzenegger's brain
Previous
Reply
Map
View

Click here to load this message in the networking platform