日期:2014-05-17  浏览次数:21107 次

文本框显示数字格式?
怎样设置?
1,234,567,890.55

------解决方案--------------------
2500000.ToString("N")

2,500,000.00
------解决方案--------------------
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
  public class Form1 : Form
  {
    TextBox tb = new TextBox();
    public Form1()
    {
      tb.TextChanged += new EventHandler(tb_TextChanged);
      Controls.Add(tb);
    }

    void tb_TextChanged(object sender, EventArgs e)
    {
      string value = tb.Text.Replace(",", "");
      ulong ul;
      if (ulong.TryParse(value, out ul))
      {
        tb.TextChanged -= tb_TextChanged;
        tb.Text = string.Format("{0:#,#}", ul);
        tb.SelectionStart = tb.Text.Length;
        tb.TextChanged += tb_TextChanged;
      }
    }
  }
}


http://social.msdn.microsoft.com/Forums/en-US/98887be8-814c-47e1-8110-c2442ce1640b/how-to-seprate-digits-with-comma-in-textbox
------解决方案--------------------
private void textBox1_Leave(object sender, EventArgs e)
{
      int num = int.Parse(textBox1.Text);
      textBox1.Text = string.Format(num.ToString("N"));
}