Here is what you need (I hope):
------------------------- CurrencyTextBox Validator.cs
using System;
using System.Componen tModel;
using System.Collecti ons;
using System.Diagnost ics;
using System.Windows. Forms;
namespace YourApp
{
/// <summary>
/// Summary description for CurrencyTextBox Validator.
/// </summary>
public class CurrencyTextBox Validator : System.Windows. Forms.TextBox
{
char keyCharValue;
public CurrencyTextBox Validator()
{
InitializeCompo nent();
}
#region Initialize
private void InitializeCompo nent()
{
this.KeyPress += new
System.Windows. Forms.KeyPressE ventHandler(thi s.CurrencyTextB ox_KeyPress);
this.BorderStyl e = System.Windows. Forms.BorderSty le.FixedSingle;
this.TextChange d += new EventHandler(th is.CurrencyText Box_TextChanged );
}
#endregion
#region public methods
/// <summary>
/// Get the Currency Value (without space) of the TextBox
/// </summary>
/// <returns> -1 when an error occurs</returns>
public int GetValueOfCurre ncy()
{
try
{
if (this.Text != "")
return (Convert.ToInt3 2(this.Text.Rep lace(" ", "")));
else
return -1;
}
catch(Exception )
{
return -1;
}
}
/// <summary>
/// Take the Currency Value (without space) and put it in the TextBox
/// </summary>
public void PutCurrencyIn(s tring currencyValue)
{
this.Text = currencyValue;
AddSpaceInNumbe r();
}
#endregion
#region private methods
private void AddSpaceInNumbe r()
{
for (int posOfSpaceInTex t = this.Text.Lengt h; posOfSpaceInTex t > 3;
posOfSpaceInTex t -= 3)
this.Text = this.Text.Inser t(posOfSpaceInT ext - 3, " ");
}
#endregion
#region mask handlers
private void CurrencyTextBox _KeyPress(objec t sender,
System.Windows. Forms.KeyPressE ventArgs e)
{
keyCharValue = e.KeyChar;
}
private void CurrencyTextBox _TextChanged(ob ject sender, System.EventArg s
e)
{
this.TextChange d -= new EventHandler(th is.CurrencyText Box_TextChanged );
if (!Char.IsDigit( keyCharValue) && keyCharValue != ' ' &&
Convert.ToInt32 (keyCharValue) != 8)
{
this.Text = this.Text.Repla ce(keyCharValue .ToString(), "");
this.Select(thi s.Text.Length, 0);
}
else
{
this.SuspendLay out();
this.Text = this.Text.Repla ce(" ", "");
AddSpaceInNumbe r();
this.Select(thi s.Text.Length, 0);
this.ResumeLayo ut();
}
this.TextChange d += new EventHandler(th is.CurrencyText Box_TextChanged );
}
#endregion
}
}
------------------------
Best regards.
--
Aymeric GAURAT APELLI
Consultant 3IE (
http://www.3ie.org)
"Dmitry Karneyev" <ka******@msn.c om> wrote in message
news:ut******** ******@TK2MSFTN GP09.phx.gbl...
How to make TextBox control that allows to input only numerics, currency
etc ?
Or can I download such stuff ?