Reputation: 995
I am trying to add the sum of two numbers such as 350 + 400 to a Masked Textbox using a button. I am sorry I am pretty new to C#. Any help is appreciated. Thanks
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text.Sum = 350 + 400
}
Upvotes: 0
Views: 634
Reputation: 412
If the .Text property of maskedTextBox2 is a string, it will not have a .Sum property.
Try this:
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
Upvotes: 1
Reputation: 41256
Like this?
public void button_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
Unless there is some format of the MaskedTextBox that is preventing the assignment, that should be fine.
Upvotes: 0
Reputation: 22600
You really just want the sum to show up in the textbox, right? So really, you just need to work with the Text
property of the box.
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = 350 + 400
}
Upvotes: 1
Reputation: 13756
masketTexBox2.Text = (350+400).ToString();
This can help. Appending value to textbox control is done throught .Text property. And at the end, I just converted sum into string
Upvotes: 2
Reputation: 57593
Try this:
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
Upvotes: 1
Reputation: 112865
You just need to set the MaskedTextBox.Text
property. Note that the result of 350 + 400
will be of type System.Int32
; however, MaskedTextBox.Text
is a System.String
. C# will not perform the type conversion implicitly (you'll get a compile-time error), so you need to convert the result of this addition to a string. Here's an example:
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
For more information on types, see this MSDN page.
Upvotes: 5
Reputation: 58625
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
Upvotes: 3