form有三个textbox, 我要计算textbox三个数的总和(double类型),在不用try..catch的情况下,怎样可以实现这三个数相加而不出错呢?要考虑textbox输入的可能是字符,或者输入的不是三个数,可能只输入一个数,或者两个数。ps:之前我是这样写的,但是好像是因为有返回值不能用try..catch
public double count(string m, string w, string f)
{
double sum = double.Parse(m) + double.Parse(w) + double.Parse(f);
return sum;
}
public double count(string m, string w, string f)
{
double sum = double.Parse(m) + double.Parse(w) + double.Parse(f);
return sum;
}
解决方案 »
- wpf的RichTextBox能不能做到这样的效果:当鼠标移动到某些高亮字的时候,ToolTip出现,提示相关信息?
- 关于Common Control的本地化问题
- DataGrid中画出多行表头后,如何进行排序啊??请高手指教
- 如何把menu的click用代碼指給某button的click事件。
- 循环插入数据问题
- ComboBox如何绑定数据库中的文本和编号的字段啊
- 求助,如何自动查找WebBrowser控件中当前网页的内容
- 用ArrayList实现链表功能的一个疑问, 请大家帮忙!
- 用那一款工具做GIF,比较方便?
- 关于消息发送,在线等待!!!
- C# socket 接收图片报错
- c# 双精度数据,怎么取整数部分,和小数部分?
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
int kc = Convert.ToInt32(e.KeyChar);
if ((kc < 48 || kc > 57) && kc != 8)
e.Handled = true;
}
public double count(string m, string w, string f)
{
double a, b, c;
double.TryParse(m, out a);
double.TryParse(w,out b);
double.TryParse(f,out c);
return a + b + c; }
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);而且有bug,不吃小数点
这样不会导致程序异常结束如果不想有任何提示的话, 可以在catch块布做任何处理的
94,不加try catch你的程序漏洞就会很多的
点右键,粘贴,也要禁止
新建右键菜单contextMenuStrip1,菜单项为空,textbox的ContextMenuStrip属性设为contextMenuStrip1