添加两个包含int值的标签 [英] adding two label which contains int value
问题描述
我有两个不同形式的标签。表单4和form6,
包含两个int值,我想添加那个int值并显示在form4中,
所以我在发件人表单中这样做了这是form6,
这段代码是正确的并且它没有产生任何错误,所以为什么不在表格中更新标签4
此代码在按钮点击中事件
< pre> private void button2_Click(object sender,EventArgs e)
{
Form4 fl = new Form4();
int f;
f = Convert.ToInt32(labelofform6.Text);
int g;
g = Convert.ToInt32(fl.labelofform4.Text);
fl.label1.Text = f.ToString()+ g.ToString();
}
;
fl.label1.Text = f.ToString()+ g.ToString( );
此行不会执行数学加法其字符串添加
例如:
int f = 10 ;
int g = 20 ;
f1.label1.Text = f.ToString()+ g.ToString();
o / p将是1020而不是30
对于数学加法,只需添加两个int变量,如下所示
int f = 10 ;
int g = 20 ;
f1.label1.Text = Convert.ToString(f + g);
/ EDIT
在你的情况下Form4 f1 = new Form4()是一个局部变量,它具有成员labelofform4的空值或默认值。文字,因为你没有更新它。
秒你说它不工作我没有看到任何代码显示form4是不包括在任何目的?
/ EDIT
int f = 10 ;
int g = 20 ;
int sum = 0 ;
sum = f + g;
f1.label1.Text = Sum.ToString();
// 你试图添加字符串f1.label1.Text = f.ToString() + g.ToString();
// 不是实际值
i have two labels in different form. form 4 and form6,
which contains two int value, i want to add that int value and show up in the form4,
so i have done this in the sender form which is form6,
this code is correct and it is not generating any error, so why not the label is not updating in the form4
this code is in the button click event
<pre>private void button2_Click(object sender, EventArgs e) { Form4 fl = new Form4(); int f; f = Convert.ToInt32(labelofform6.Text); int g; g = Convert.ToInt32(fl.labelofform4.Text); fl.label1.Text= f.ToString() + g.ToString() ; }
;
fl.label1.Text= f.ToString() + g.ToString() ;
this line wont perform the mathematical addition its string addition
for eg:
int f = 10; int g = 20; f1.label1.Text = f.ToString() + g.ToString() ;
o/p will be 1020 and not 30
For mathematical addition just add two int variable as below
int f = 10; int g = 20; f1.label1.Text = Convert.ToString(f + g);
/EDIT
In your case Form4 f1 = new Form4() is a local variable which has an empty value or a default value for the member labelofform4.Text because you are not updating it.
second you said its not working I dont see any code to display the form4 was is not included for any purpose?
/EDIT
int f = 10; int g = 20; int sum=0; sum=f+g; f1.label1.Text = Sum.ToString(); //u r trying to add string f1.label1.Text = f.ToString() + g.ToString() ; //not the actual value
这篇关于添加两个包含int值的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!