如何在usercontrol中改善我的double.Parse属性 [英] How to improve my double.Parse property in usercontrol

查看:131
本文介绍了如何在usercontrol中改善我的double.Parse属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UserControl上有以下代码,由单个文本框组成.

I have the following code on a UserControl, consisting of a single textbox.

public double txt
{
    get { return double.Parse(txtInputSmall.Text); }
    set { txtInputSmall.Text = value.ToString(); }
}

public string text
{
    get { return txtInputSmall.Text; }
    set { txtInputSmall.Text = value; }
}


我想要可以处理double的东西,像这样在这里为我解析,这样我就不必为添加到WinForm的每个UserControl都进行解析.问题是,当我进入WinForm的设计视图时,我不断收到以下消息:


I want something that handles the double.Parse for me, like here, so that I don''t need to do it for every UserControl I add to my WinForm. The problem is, when my I''m in design view of my WinForm, I keep getting the following message:

Code generation for property 'txt' failed. Error was: 'Property accessor 'txt' on object 'inputcontrolSmall12' threw the following exception: "Input string was not in a correct format"


我认为设计人员希望文本框中的字符串为double,而不是double,因为它为空.我该如何改进这段代码?


I think the designer expects the string in the textbox to be a double, which is not, because it''s empty. How can I improve this piece of code?

推荐答案

如果要解析双精度型,请使用
If you want to parse a double, then use the Double.TryParse[^] method provided by the framework.


这篇关于如何在usercontrol中改善我的double.Parse属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆