Reputation: 43
I am using one thread running this code:
try
{
Form1 f = getForm<Form1>();
f.changePrice(price);
}
catch (Exception e)
{
Console.WriteLine("error: " + e);
}
Here is the changePrice
method:
public void changePrice(Int32 price)
{
txtPrice.Text = ""+price;
}
I want to add text to my textbox "txtPrice".
Upvotes: 0
Views: 1667
Reputation: 1163
You should change your textbox text at runtime like this.
public void changePrice(Int32 price)
{
if (InvokeRequired)
{
this.Invoke(new Action<Int32>(changePrice), new object[] { price });
return;
}
txtPrice.Text = ""+ price;
}
This will do the trick.
Upvotes: 1
Reputation: 62498
convert it to string
as Text
property is of type string
:
public void changePrice(Int32 price)
{
txtPrice.Text = price.ToString();
}
Upvotes: 1