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

1

People, I have a boring problem. I wanted to put the text I took from one textbox and put in another that is set to 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 a layman on the subject so I wanted to know what I can do. I do not know if what I'm trying to do is valid so I tried to do it with a label but I also encountered complications. Does anyone have a light?

    
asked by anonymous 12.08.2017 / 07:11

1 answer

1

A TextBox even when defined with the ReadOnly to True attribute can have its text programmatically altered by directly modifying the Text field:

nomeDaMinhaTextbox.Text = "outro texto aqui";

Or as in your case, coming from a previously built variable:

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

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

However, if the user will never be able to directly change what is in TextBox and it is only for visualization the best would be to use a Label . The way to assign text in Label is exactly equal to TextBox .

    
12.08.2017 / 11:39