当前位置 - 股票行情交易網 - 文娛動態 - c# 如何在文本框中輸入數字讓它自動生成價錢的格式 如:¥100,000.00

c# 如何在文本框中輸入數字讓它自動生成價錢的格式 如:¥100,000.00

private void textBox1_Enter(object sender, System.EventArgs e)

{

object tag = this.textBox1.Tag;

if (tag == null)

{

return;

}

this.textBox1.Text = tag.ToString();

}

private void textBox1_Leave(object sender, System.EventArgs e)

{

string text = this.textBox1.Text;

this.textBox1.Tag = text;

try

{

double val = Convert.ToDouble(text);

this.textBox1.Text = val.ToString("¥#,###.00");

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

this.textBox1.SelectAll();

this.textBox1.Focus();

}

}