Adding up a sum of 2 numbers into A Masked Textbox
I am trying to add the sum of two numbers such as 350 + 400 to a Masked Tex开发者_Go百科tbox 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
}
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.
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
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
Try this:
private void button11_Click(object sender, EventArgs e)
{
maskedTextBox2.Text = (350 + 400).ToString();
}
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
}
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();
}
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.
精彩评论