这是该程序的屏幕截图。正如你所看到的,我按照我想要的方式设置了输出格式。我使用了这段代码:<DataGridTextColumn Header="Price" Binding="{Binding Path=Price, StringFormat=C, ConverterCulture='de-DE'}"/>
如何使文本框仅接受数字作为货币格式作为输入,或者如何使其在键入时自动格式化?我尝试了一些我在这里和那里找到的代码,但它不起作用。希望有人可以帮助我并给我一些详细信息。数据必须保存在SQL Server数据库中,到目前为止我使用的是LINQ。
您可以创建一个 TextChanged 事件并随时设置文本格式。
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.Text = string.Format("{0:#,##0.00}", double.Parse(textBox1.Text));
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
从以下地方得到这个:https://stackoverflow.com/a/15473340/5588364 https://stackoverflow.com/a/15473340/5588364
And:
https://stackoverflow.com/a/463335/5588364 https://stackoverflow.com/a/463335/5588364
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)