委托事件中调用的函数中还有函数调用,且带参变量,但这种方法无法执行,请问采取什么样的方法能够解决这样的问题??
private delegate void CallData();//定义委托
System.Timers.Timer timer = new System.Timers.Timer();//全局监控计时器 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Data();
//throw new NotImplementedException();
} #region 自定义函数
void Data()
{
// InvokeRequired需要比较调用线程ID和创建线程ID
// 如果它们不相同则返回true
if (A101.InvokeRequired)
{
CallData cd = new CallData(this.setdata);
this.BeginInvoke(cd);
}
else
{
this.setdata();
}
}
void setdata()
{
this.DataShow(A101, t101, (clsE3)DeviceE3Var.LstE3[163], true);//A101:控件名称 }
public void DataShow(ControlLibrary.Labels lab, ControlLibrary.Titles title, clsE3 e3tmp, Boolean e3run)
{
title.Model = true;
if (e3run == true)//设备启动e3运行
{
lab.Lab1 = Convert.ToString(e3tmp.JianShi[4]); //平均电流
lab.Lab2 = Convert.ToString(e3tmp.JianShi[9]); //已用热容量百分比
lab.Lab3 = Convert.ToString(e3tmp.JianShi[11]); //电流不平衡百分比
}
else//设备停止运行
{
lab.Lab1 = "0";
lab.Lab2 = "0";
lab.Lab3 = "0";
}
}
private delegate void CallData();//定义委托
System.Timers.Timer timer = new System.Timers.Timer();//全局监控计时器 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Data();
//throw new NotImplementedException();
} #region 自定义函数
void Data()
{
// InvokeRequired需要比较调用线程ID和创建线程ID
// 如果它们不相同则返回true
if (A101.InvokeRequired)
{
CallData cd = new CallData(this.setdata);
this.BeginInvoke(cd);
}
else
{
this.setdata();
}
}
void setdata()
{
this.DataShow(A101, t101, (clsE3)DeviceE3Var.LstE3[163], true);//A101:控件名称 }
public void DataShow(ControlLibrary.Labels lab, ControlLibrary.Titles title, clsE3 e3tmp, Boolean e3run)
{
title.Model = true;
if (e3run == true)//设备启动e3运行
{
lab.Lab1 = Convert.ToString(e3tmp.JianShi[4]); //平均电流
lab.Lab2 = Convert.ToString(e3tmp.JianShi[9]); //已用热容量百分比
lab.Lab3 = Convert.ToString(e3tmp.JianShi[11]); //电流不平衡百分比
}
else//设备停止运行
{
lab.Lab1 = "0";
lab.Lab2 = "0";
lab.Lab3 = "0";
}
}
解决方案 »
- 怎样拦截控件的某个事件?
- C#页面身份验证怎么做,要从web.config里配置的
- 求助
- 如何在点击gridview中的按钮控件时,触发onrowdeleting的事件
- 最近比较头疼的问题是c#的验证正则表达式,这东西怎么写,有没有教程,大家指点小弟!
- 求 SharphSql 类库和源代码
- --- 高分求解 --- !!!请教高手!!! 如何编写强制与其他程序沟通的WIN程序 ,内详,暂时只有70分,解决后分不是问题,谢谢!
- 高分,虚心求教!!!
- Winform中,如何让普通button当被点击时有被压下去的效果?
- throw exception 问题:
- 如何取得最后执行的SQL语句?
- VS2005 c# 数据源 新建连接失败!
{
this.Enabled = false;
//funOcr(imageViewer1.ImageSouce);
this.progressBar1.Maximum = imageViewer1.ImageSouce.Length *2+ 5;
dlgtOCR dg = new dlgtOCR(funOcr);
IAsyncResult ia ;
ia = dg.BeginInvoke(imageViewer1.ImageSouce,new AsyncCallback(funCallBack),dg);
} private void endOCR()
{
this.progressBar1.Value = progressBar1.Maximum;
progressBar1.Visible = false;
this.progressBar1.Value = 0;
label2.Visible = false;
this.Enabled = true;
frmFilesIn fi = new frmFilesIn(PublicInfo.prtyAppTmpPath + "all.rtf");
this.AutoScroll = true;
fi.AutoScroll = true;
//frmFI.FileName =
PublicInfo.prptyOcrDoc = true;
PublicInfo.picFileName = imageViewer1.ImageSouce;
fi.Show();
fi.MdiParent = (Form)this.Tag;
Control ct = this.Parent;
this.Parent = null;
this.MdiParent = fi.MdiParent;
this.MdiParent.LayoutMdi(MdiLayout.TileVertical);
Point p1 = this.Location;
Point p2 = fi.Location;
this.Height = ct.Height;
fi.Height = ct.Height;
fi.Parent = ct;
this.Parent = ct;
this.Location = p1;
fi.Location = p2;
}
void funCallBack(IAsyncResult ia)
{
dlgtOCR dg =(dlgtOCR)ia.AsyncState;
dg.EndInvoke(ia);
dlgtEndOcr dgs = new dlgtEndOcr(endOCR);
this.Invoke(dgs);
}
void funShowBar(int i,string mesg)
{
if (this.InvokeRequired)
{
dlgtShowBar dg = new dlgtShowBar(funShowBar);
this.Invoke(dg, new object[] { i ,mesg});
}
else
{
if (i < progressBar1.Maximum)
{
progressBar1.Visible = true;
label2.Visible = true;
this.progressBar1.Value = i;
label2.Text = mesg;
}
else
{
progressBar1.Visible = false;
label2.Visible = false;
}
}
} delegate void dlgtOCR(string[] strImg);
delegate void dlgtShowMessage(string strIn, Control ct);
delegate void dlgtShowBar(int i,string mesg);
delegate void dlgtEndOcr();
private void funOcr(string[] strImg)
{
}
private int k = 0; ///这是我定义的一个新的字段
private delegate void CallData();//定义委托
System.Timers.Timer timer = new System.Timers.Timer();//全局监控计时器 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
this.Data();
//throw new NotImplementedException();
} #region 自定义函数
void Data()
{ k = 20; //使用这个字段。
// InvokeRequired需要比较调用线程ID和创建线程ID
// 如果它们不相同则返回true
if (A101.InvokeRequired)
{
CallData cd = new CallData(this.setdata);
this.BeginInvoke(cd);
}
else
{
this.setdata();
}
} 从上面推荐你可以看出来怎么做了。
dlgtOCR dg = new dlgtOCR(funOcr);
dg.BeginInvoke(imageViewer1.ImageSouce,null,null);
上面的红色部分就是参数这个简单的委托示例,
dlgtOCR dg = new dlgtOCR(funOcr);
dg.BeginInvoke(imageViewer1.ImageSouce,null,null);
上面的红色部分就是参数这个简单的委托示例,
dlgtOCR dg = new dlgtOCR(funOcr);
dg.BeginInvoke(imageViewer1.ImageSouce,null,null);
上面的红色部分就是参数这个简单的委托示例,
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
} private delegate void CallData(); private void button1_Click(object sender, EventArgs e)
{
this.Data();
} void Data()
{
CallData cd = new CallData(this.setData);
this.BeginInvoke(cd);
} void setData()
{
this.DataShow(this.textBox1.Text);
} public void DataShow(string s)
{
this.textBox2.Text = s;
}
}
委托事件中也是可以有函数的,参照以上。