我必须为标记实现代码,所以我无法插入字符值帮助我 [英] I Have To Implement A Code For Marks So I Can't Insert The Character Values Help Me
本文介绍了我必须为标记实现代码,所以我无法插入字符值帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
double n1, n2, n3, n4, n5, n6;
float res;
// n1 = Convert.ToInt32(txttui.Text);
n1 = Convert.ToDouble(textBox1.Text);
n2 = Convert.ToDouble(textBox2.Text);
n3 = Convert.ToDouble(textBox3.Text);
n4 = Convert.ToDouble(textBox4.Text);
n5 = Convert.ToDouble(textBox5.Text);
n6 = Convert.ToDouble(textBox6.Text);
// n6 = Convert.ToInt32(txthostl.Text);
res = n1 + n2 + n3 + n4 + n5 + n6;
//txttotalfee.Text = Convert.ToString(res);
textBox27.Text = Convert.ToString(res);
推荐答案
我认为你试图阻止用户输入字符值。如果这是你的问题,那么我在互联网上找到了以下源代码。您可以使用此权限。
I think you are trying to prevent users to input character values. If this is your question then I have found below source code on internet. You can user this.
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;
}
}
您可以使用相同的方法文本框。
You can use the same method for all your textboxes.
您好,
我建议您阅读以下文章:
WPF中的简单验证 [ ^ ]
祝你好运,
Stephan
Hi,
I would like to suggest reading the following article:
Simple Validation in WPF[^]
Best regards,
Stephan
这篇关于我必须为标记实现代码,所以我无法插入字符值帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文