CurrencyTextBox from StrataFrame TextBox


Author
Message
Rogerio Mauri
Rogerio Mauri
StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)StrataFrame User (303 reputation)
Group: StrataFrame Users
Posts: 205, Visits: 629
Hi...

Creating a component for edition of a field currency from a class base of the StrataFrame.

Success !!!

Rogério Smile
http://blog.licitec.com.br


using System;
using System.Collections.Generic;
using System.Text;

namespace Licitec.StrataFrame.WinForms
{
    public class CurrencyTextBox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox
    {
        protected override void OnValidating(System.ComponentModel.CancelEventArgs e)
        {
            System.Globalization.CultureInfo culture;
            culture = System.Globalization.CultureInfo.CreateSpecificCulture("pt-BR");
            decimal result;

            if (this.Text.Trim() != string.Empty && !decimal.TryParse(this.Text, System.Globalization.NumberStyles.Currency, culture, out result))
            {
              
                this.HideSelection = false;
                this.SelectAll();
                System.Windows.Forms.MessageBox.Show("Entre com um valor válido.");
                this.HideSelection = true;
                e.Cancel = true;
            }

            base.OnValidating(e);
        }

        protected override void OnValidated(EventArgs e)
        {
            decimal result;
            if (this.Text.Trim() == string.Empty)
            {
                result = 0;
            }
            else
            {
                result = Decimal.Parse(this.Text, System.Globalization.NumberStyles.Currency);
            }
            this.Text = result.ToString("c");

            base.OnValidated(e);
        }

        protected override void OnEnter(EventArgs e)
        {
            System.Globalization.CultureInfo culture;
            culture = System.Globalization.CultureInfo.CreateSpecificCulture("pt-BR");
            decimal result;
            if (decimal.TryParse(this.Text, System.Globalization.NumberStyles.Currency, culture, out result))
            {
                this.Text = result.ToString();
            }

            base.OnEnter(e);
        }
    }
}


Rogério Mauri Smile



Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hey, Rogério...

Great! Wink

Valeu... Cool

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search