如何将整数值从一个控制块传递给另一个控制块? [英] How to pass integer value form one block of control to another ?
本文介绍了如何将整数值从一个控制块传递给另一个控制块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我做了一个在块中有整数值的代码。我已将此值传递给按钮单击事件上的另一个块,但我想将相同的整数值传递给第3个块。我做了这段代码:
void wc_DownloadStringCompleted1( object sender,DownloadStringCompletedEventArgs e)
{
...
dynamic num = label1 .Bottom +(i * 30 );
button1.Click + = new EventHandler((sender1,e1)= > button1_Click(发件人,e,num);
}
我已将此整数值传递给以下代码:
void browsebutton_Click( object sender,DownloadStringCompletedEventArgs e,< span class =code-keyword> int num)
{
...
wc.DownloadStringCompleted + = wc_DownloadStringCompleted2;
// [取而代之的我也尝试了这个:wc.DownloadStringCompleted + = new // DownloadStringCompletedEventHandler((sndr,ev)=> wc_DownloadStringCompleted2(发件人, e,// num));但是当我使用它时控件不会进入第3块]
}
现在我想要将该num值传递给下一个块
void wc_DownloadStringCompletedbrowse2( object sender,DownloadStringCompletedEventArgs e)
{
....
}
请任何人给我任何建议。
谢谢。
解决方案
将 num
更改为类的成员变量,可以从该类的所有函数/属性访问它
Hello, I did a code which have an integer value in a block. I have passed this value to another block on button click event but I want to pass the same integer value to the 3rd block. I did this code :
void wc_DownloadStringCompleted1(object sender, DownloadStringCompletedEventArgs e)
{
...
dynamic num = label1.Bottom + (i * 30);
button1.Click += new EventHandler((sender1, e1) => button1_Click(sender, e, num);
}
I have passed this integer value to the following code :
void browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, int num)
{
...
wc.DownloadStringCompleted += wc_DownloadStringCompleted2;
//[In its place I also tried this : wc.DownloadStringCompleted +=new //DownloadStringCompletedEventHandler((sndr, ev) => wc_DownloadStringCompleted2(sender, e, //num)); but when I used this the control is not going to the 3rd block]
}
Now I want to pass that num value to the following block
void wc_DownloadStringCompletedbrowse2(object sender, DownloadStringCompletedEventArgs e)
{
....
}
Please any one give me any suggestion.
Thanks.
解决方案
Change num
into a member variable of the class, it will be accessible from all functions/properties of that class then.
这篇关于如何将整数值从一个控制块传递给另一个控制块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文