[英]How can I clear a TextBox?
I have a pretty decent background in Java and C++, but I'm struggling to do something trivial in C#. 我在Java和C ++方面有相当不错的背景,但是我正在努力在C#中做一些琐碎的事情。 I have two
TextBoxes
: MessageBox
and SenderBox
. 我有两个
TextBoxes
: MessageBox
和SenderBox
。 I want to send the text from SenderBox
to MessageBox
(which is easy), but I want to clear SenderBox
once that is done. 我想将文本从
SenderBox
发送到MessageBox
(这很简单),但是一旦完成,我想清除SenderBox
。 The following is basically the code that is fired when you press Enter to send the text: 以下基本上是按Enter键发送文本时触发的代码:
string temp = SenderBox.Text;
SenderBox.Text = "cleared";
MessageBox.Text = temp;
Most programming languages are somewhat procedural or at least execute in some orderly way. 大多数编程语言都是过程性的,或者至少以某种有序的方式执行。 Why does C#/WPF for Windows 8 apps seem to defy this standard?
为什么Windows 8应用程序的C#/ WPF似乎违反了此标准? You would expect temp to be set equal to the value of
SenderBox
, first of all. 首先,您希望将temp设置为等于
SenderBox
的值 。 If you look at the code, temp
should not equal "cleared" unless that's what SenderBox
contains. 如果看一下代码,除非
SenderBox
包含temp
否则temp
不应等于“ cleared”。 At that point (line 1), it doesn't. 在那一点(第1行)上没有。 I tried to create a
send(msg)
function to dereference the weird string, but that didn't change a thing. 我试图创建一个
send(msg)
函数来解除对奇怪字符串的引用,但这并没有改变任何事情。 The following code runs as expected: 以下代码按预期运行:
string x = "abc";
string y = x;
y = "123";
MessageBox.Text = x;
Can someone enlighten me? 有人可以启发我吗? Not sure what's going on here.
不知道这是怎么回事。
If you're not trying to switch the contents of the two boxes, why not just do: 如果您不打算切换两个框的内容,为什么不这样做:
MessageBox.Text = SenderBox.Text;
SenderBox.Text = "cleared";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.