怎么能这样做TextBox3 [英] How can do That to TextBox3
问题描述
我创建3个文本框
1:文本框1 = 15.0;
2:文本框2 = .10;
3:文本框3 = 15.0 * .10之类(文本框1) *文本框2)
如何对TextBox3
引用:当textbox3 click事件写一个方法来乘以值
1.双单击TextBox3以获取Click事件处理程序代码。
2.在该事件中捕获其他两个文本框中的信息 - 您的注释中的代码已关闭,但您需要使用类似 double.TryParse [ ^ ](注意,链接是针对int.TryParse的,但是对于支持TryParse方法的所有数据类型,原则是相同的)
3.进行计算
4.将结果放入TextBox3 - 提示你需要ToString()
方法,你可能想要格式化字符串 [ ^ ]
其他提示:
- 你真的想用int
? (根据你的评论)。您的示例数据不使用整数。您可能需要限制输入数字的大小。或者选择其他数据类型。
试试这个:
decimal x,y;
bool isXValid = decimal .TryParse(Textbox1.Text, out x);
bool isYValid = decimal .TryParse(Textbox2.Text, out y);
if (isXValid&& isYValid)
Textbox3.Text =(x * y).ToString();
else
Textbox3.Text = 输入无效;
了解详情:
1. http://csharp.net-informations.com/gui/cs-textbox.htm [ ^ ]
2. https://msdn.microsoft.com/en-us/library/9zbda557%28v=vs.110%29 .aspx [ ^ ]
I Create 3 Text Boxs
1:Textbox 1 =15.0;
2:Textbox 2 = .10;
3:Textbox 3 = 15.0 * .10 like (Textbox 1 * Textbox 2)
How can do That to TextBox3解决方案Quote:when textbox3 click event write a method for multipy the values
1. Double-click on TextBox3 to get to the Click event handler code.
2. In that event capture the information in the other two textboxes - your code in your comment is close but you need to use something like double.TryParse[^] (NB the link is for int.TryParse but the principles are the same for all datatypes that support the TryParse method)
3. Do your calculation
4. Put the results into TextBox3 - hint you will need theToString()
method, and you might want to format the string[^]
Other hints:
- do you really want to useint
? (as per your comment). Your sample data does not use integers. You might need to limit the size of the numbers entered. Or choose another data type.
Try this:
decimal x, y; bool isXValid = decimal.TryParse(Textbox1.Text, out x); bool isYValid = decimal.TryParse(Textbox2.Text, out y); if (isXValid && isYValid) Textbox3.Text = (x * y).ToString(); else Textbox3.Text = "Invalid input";
Learn more:
1. http://csharp.net-informations.com/gui/cs-textbox.htm[^]
2. https://msdn.microsoft.com/en-us/library/9zbda557%28v=vs.110%29.aspx[^]
这篇关于怎么能这样做TextBox3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!