private void TXT_STD_SALES_AMT_TextChanged(object sender, EventArgs e) { //Remove previous formatting, or the decimal check will fail including leading zeros string value = TXT_STD_SALES_AMT.Text.Replace(",", "") .Replace("$", "").Replace(".", "").TrimStart('0'); decimal ul; //Check we are indeed handling a number if (decimal.TryParse(value, out ul)) { //Unsub the event so we don't enter a loop TXT_STD_SALES_AMT.TextChanged -= TXT_STD_SALES_AMT_TextChanged; //Format the text as currency string tmp_value = string.Format(CultureInfo.CreateSpecificCulture("en-US"), "{0:n0}", ul); TXT_STD_SALES_AMT.Text = tmp_value.Replace("$", ""); TXT_STD_SALES_AMT.TextChanged += TXT_STD_SALES_AMT_TextChanged; TXT_STD_SALES_AMT.Select(TXT_STD_SALES_AMT.Text.Length, 0); TXT_STD_TAX_AMT.TextChanged -= TXT_STD_TAX_AMT_TextChanged; TXT_SUT_TAX_AMT.TextChanged -= TXT_SUT_TAX_AMT_TextChanged; calAccAmt(false, true); TXT_STD_TAX_AMT.TextChanged += TXT_STD_TAX_AMT_TextChanged; TXT_SUT_TAX_AMT.TextChanged += TXT_SUT_TAX_AMT_TextChanged; } }
private void COM_STD_NIGHT_SelectedIndexChanged(object sender, EventArgs e) { if (COM_STD_NIGHT.SelectedIndex <= 0) { TXT_STD_SALES_AMT.Text = "0"; TXT_STD_TAX_AMT.Text = "0"; TXT_STD_SALES_AMT.Enabled = false; } else { TXT_STD_SALES_AMT.Enabled = true; TXT_STD_SALES_AMT.Focus(); TXT_STD_SALES_AMT.SelectAll(); } }