从文本框中输入 [英] Taking input from text box

查看:76
本文介绍了从文本框中输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我是wpf的新手.请在这方面帮助我.
在MFC中,我们使用Update(True)或Update(False)更新控件(例如文本框).我们如何使用WPF?
我取两个名为firstTextBox和secondTextBox的文本框.现在我希望用户从键盘上的两个文本框中输入两个整数,然后单击按钮(例如AddButton),我的应用程序将它们添加并在第三个文本框中显示结果,即thirdTextBox(三个文本框和一个按钮是在名为myCanvas的画布上拍摄的. WPF中的代码是什么?

问候

Hi!
I am newcomer in wpf. Plz help me in this regard.
In MFC we updates controls(e.g textbox)with Update(True) or Update(False). How we do in WPF?
I take two textbox with name firstTextBox and secondTextBox.Now i want that user inputs two integer from keyboard in two textboxes and on clicking of a button (say AddButton) my application add them and display the result in third textbox i.e, thirdTextBox (Three textboxes and one button were taken on a canvas with name myCanvas). What will be the code in WPF?

regards

推荐答案

这个问题与Update无关.使用.NET控件(不仅适用于WPF,甚至不仅适用于UI),您都不需要任何特殊的更新,因为所有必需的控件表示无效都通过它们的属性执行.更改属性值后,属性设置器的代码将调用属性分配所需的副作用.

如果是System.Windows.Controls.TextBox,则通过为其属性string Text分配一个值来更新(尤其是).

请参阅: http://msdn.microsoft.com/en-us/library /system.windows.controls.textbox.aspx [
This question has nothing to do with Update. With .NET controls (not only for WPF, and not even only for UI), you don''t need any special updating, because all required invalidation of the presentation of the controls are performed through their properties. When a property value is changed, the code of the property setter invokes required side effect of property assignment.

In case of System.Windows.Controls.TextBox, it is updated by assignment a value to its property string Text (in particular).

Please see: http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.aspx[^].

This property is all you need to solve the problem. Also, as the property is of the string type, and you need to work with int, you will need to parse a string to an integer value and present the integer value as a string, so you will need to use int.Parse (throws exception in case of invalid numeric format) or int.TryParse (returns Boolean value depending on success) and int.ToString.

Now, that''s really all you need.

—SA


这篇关于从文本框中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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