zoukankan      html  css  js  c++  java
  • 委托 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);//执行委托实例  
            }
    }
    View Code
    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;
                    }
                }
            }
    View Code
  • 相关阅读:
    简直不敢相信...
    halcon 保存Region [原创]
    VS2015 下载链接
    C#【数据转换】十进制yte[]相互转换
    C# 复制窗体问题完美解决办法
    TextBox 保持固定长度,添加新行滚动到最后,跨线程。
    mysql isnull
    C#跨线程访问控件[我的记录]
    C# 常用类-IO-ClassExcelExport
    C# 常用类-IO-ClassXML
  • 原文地址:https://www.cnblogs.com/lvk618/p/3749956.html
Copyright © 2011-2022 走看看