如何更改文本框的值 [英] How to change value of textbox
本文介绍了如何更改文本框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi
如何通过更改NumericUpDown的值来更改文本框的值?
当我向NumericUpDown赋值时,我需要文本框取值NumericUpDown
Hi
How to change value of textbox by changing the value of NumericUpDown?
I need the textbox to take the value of NumericUpDown when I assing some value to NumericUpDown
推荐答案
使用属性TextBox.Text
,它是一个读/写属性。
如果你为NumericUpDown
分配一些值,你不需要做任何其他事情。如果用户更改NumericUpDown
的值,它将无法工作;在这种情况下,处理事件NumericUpDown.ValueChanged
;在处理程序的主体中,将ValueChanged.Value.ToString()
的值赋给TextBox.Text
。< br $> b $ b
Use the propertyTextBox.Text
, it is a read/write property.
You need not do anything else if you "assign some value" toNumericUpDown
. It won't work if the user changes the value ofNumericUpDown
; in this case, handle the eventNumericUpDown.ValueChanged
; in the body of the handler, assign the value ofValueChanged.Value.ToString()
toTextBox.Text
.
NumericUpDown myUpDown = new NumericUpDown();
TextBox myTextBox = new TextBox();
//...
myUpDown.ValueChanged += (sender, eventArgs) => {
myTextBox.Text = myUpDown.Value.ToString();
}
您需要做的是将事件处理程序附加到NumericUpDown控件的值更改事件,并使用该事件设置文本的text属性-box:
Hi,
What you need to do is attach an event-handler to the value-changed event of the NumericUpDown control, and use that event to set the text property of the text-box:
numericUpDown1.ValueChanged += delegate
{
this.textBox1.Text = numericUpDown1.Value.ToString();
};
试试这段代码
try this code
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
// You can change other program parts when the value changes.
this.textBox1.Text = "Value changed to " + numericUpDown1.Value.ToString();
}
}
}
这篇关于如何更改文本框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文