Tambah Separator di Textbox dengan CSharp (C#)

Berikut Code cara tambahkan separator di textbox Fungsi :
    
public string Separator(string sNominal)
        {
            double temp = 0;
            string FormatCcy = "#,##0";
            try
            {
                temp = double.Parse(sNominal.Trim().Replace(",", ""));
            }
            catch (Exception)
            {
                
            }
            return temp.ToString(FormatCcy);
        }
Cara Pengunaan : Tambahkan event di textbox (TextChanged) dengan code :
    
private void txtQty_TextChanged(object sender, EventArgs e)
        {
            if (txtQty.Text.Trim() != "")
            {
                txtQty.Text = Separator(txtQty.Text);
                txtQty.Select(txtQty.Text.Length, 1);
            }
        }
Previous
Next Post »
Thanks for your comment