Hi,
Thank you for taking time to look into my problem. I have found the answer and it is below.
-----------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Text.RegularExpressions;
using Microsoft.VisualBasic;
namespace frmMain
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string value = textBox1.Text.Replace(",", "")
.Replace("$", "").Replace(".", "").TrimStart('0');
decimal ul;
if (decimal.TryParse(value, out ul))
{
ul /= 100;
textBox1.TextChanged -= textBox1_TextChanged;
textBox1.Text = string.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:C2}", ul);
textBox1.TextChanged += textBox1_TextChanged;
textBox1.Select(textBox1.Text.Length, 0);
}
}
private bool TextisValid(string text)
{
Regex money = new Regex(@"^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$");
return money.IsMatch(text);
}
private void frmMain_Load(object sender, EventArgs e)
{
textBox1.Text = "$0.00";
}
}
}