首页 > 代码库 > 委托 C#
委托 C#
1、Form2要委托Form1来做事情就是委托;
2、在Form2中定义委托,让Form1来执行;
3、实例如下所示:
public partial class Form2 : DevComponents.DotNetBar.Office2007Form { DataSet ds; public delegate void ChangeDatagridviewEventHandler(bool topmost); public event ChangeDatagridviewEventHandler ChangeDatagridview; public w_cancel_appoint_reason() { InitializeComponent(); } private void buttonX1_Click(object sender, EventArgs e) { ChangeDatagridview(true);//执行委托实例 } }
public partial class Form1 : DevComponents.DotNetBar.Office2007Form { public Form1() { InitializeComponent(); } private void buttonX1_Click(object sender, EventArgs e) { Form2 w_car = new Form2 (); //w_car.Show(); w_car.ChangeDatagridview += new ChangeDatagridviewEventHandler(ChangeDatagridview); w_car.Show(); } } void ChangeDatagridview(bool topmost) { ds = PatientAppService.getAppPatInfo(ld_counsel_date, ls_queuename, ls_duration, ls_doctorno); dataGridViewX1.DataSource = ds.Tables[0]; ChangedColor(); } void ChangedColor() { foreach (DataGridViewRow dgv in dataGridViewX1.Rows) { //取特定列的值,列索引是INDEX // string ld_dd = dgv.Cells[5].Value as string; string ls_status = dgv.Cells[7].Value as string; //Console.WriteLine(ls_status); switch (ls_status) { case "0": dgv.DefaultCellStyle.ForeColor = Color.Red; //dataGridViewX1.RowsDefaultCellStyle.ForeColor = Color.Red; break; case "1": break; case "2": dgv.DefaultCellStyle.ForeColor = Color.Blue; //dataGridViewX1.DefaultCellStyle.ForeColor = Color.Blue; break; case "3": break; default: break; } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。