StrataFrame Forum

CurrencyTextBox from StrataFrame TextBox

http://forum.strataframe.net/Topic14533.aspx

By Rogerio Mauri - 2/22/2008

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);
        }
    }
}

By Ivan George Borges - 2/23/2008

Hey, Rogério...

Great! Wink

Valeu... Cool