windows 如何从文本框的值设置字符串值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6429906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:08:08  来源:igfitidea点击:

How to set a string value from a textbox's value

c#.netwindows

提问by James

I am trying to set a string from a TextBox value:

我正在尝试从 TextBox 值设置一个字符串:

E.g.

例如

private void testing_Click(object sender, EventArgs e)
        {

            Set <string> = TextBox.Text

        }

How can this be done?

如何才能做到这一点?

回答by Brandon

You don't need the word set, and you can drop the declaration if the string is already declared.

您不需要单词集,如果字符串已经声明,您可以删除声明。

string yourString = TextBox.Text;

回答by agent-j

private void testing_Click(object sender, EventArgs e)
{
   string textOfTextBox = ((TextBox) sender).Text;
   MessageBox.Show (textOfTextBox);
}