How to get the values of a textBox?

-1

I created an example for you to see.

The problem is as follows. I'm trying to get the value contained in the TextBox converting to a string type to be able to use in MessageBox , but it is displaying

  

System.Windows.Forms.TextBox, Text: hi

I wanted to know the correct way to capture the value of the textBox.

    
asked by anonymous 30.12.2016 / 20:48

2 answers

4

The correct ownership of TextBox is Text to retrieve or set text in this control :

Recover:

string grava = textBox1.Text;

Define:

textBox1.Text = "Novo Texto";

References:

30.12.2016 / 20:50
-2

The TextBox is of type Text . So whenever you're going to use TextBox , Label or ComboBox , at the end you have to put your type, which in this case is .Text

Try this:

var gravar = NOMEDATEXTBOX.Text;

MessageBox.Show(gravar, "Test");
    
01.01.2017 / 18:17