How do I put the value of a variable inside a textbox?

Asked

Viewed 4,847 times

3

Guys I’m having a boring problem. I wanted to put the text I took out of a textbox and put in another that this defined as readonly. I wanted it to work as a label. I tried textchange gave error.

 private void btncalcular_Click(object sender, EventArgs e)
       {
         string salario = txtsalario.Text;
         double salario_num = double.Parse(salario);
         double liquido = (salario_num * 0.12);
         double conta = (salario_num - liquido);


      }

I’m kind of a layman, so I was wondering what I could do. I don’t know if what I’m trying to do is valid so I tried to do with a label but also found complications. Someone has a light?

1 answer

3


One TextBox even when defined with the attribute ReadOnly to True can have your text modified programmatically by directly modifying the field Text:

nomeDaMinhaTextbox.Text = "outro texto aqui";

Or as in your case, from a previously constructed variable:

nomeDaMinhaTextbox.Text = conta.ToString(); //.ToString() se for um int ou double

What the ReadOnly is to prevent the user from writing to TextBox as would normally be possible.

However, if the user will never be able to directly change what is on TextBox and it is only for viewing the best would be to use a Label. How to assign the text in Label is exactly like a TextBox.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.