1. 程式人生 > >委托初始化方法實例

委托初始化方法實例

選中 this leg clas style erro controls 返回 cti

                string strBirthError = "";
                foreach (DataRow dr in dtInfo.Rows)
                {
                    card = new PatientNoBedCard();
                    //選中卡片設置效果在自定義控件中聲明了無返回值的泛型委托Action 將PatientNoBedCard作為泛型的類型參數然後在這使用Lambda表達式來初始化委托
                    card.SelectChanged = new
Action<PatientNoBedCard>(newCard => { PatientNoBedCard oldbed = this.pnlPatientCards.Controls.Cast<PatientNoBedCard>().ToList().Find(it => it.IsChecked); if (oldbed != null) { oldbed.IsChecked
= false; } newCard.IsChecked = true; }); card.ShowEnterOffice = new Action<PatientNoBedCard>(ShowOfficeBed);//聲明和初始化委托方法1 //card.ShowEnterOffice = ShowOfficeBed;//C# 2.0提出了快捷語法方法2
//card.ShowEnterOffice += ShowOfficeBed;//方法3 添加委托方法 //card.ShowEnterOffice = delegate(PatientNoBedCard card1) { };//方法4 使用匿名方法 //card.ShowEnterOffice = (newCard => { }); //方法5 使用Lambda表達式 //設置控件對應屬性 //card.LevelHl = dr["TENDLEVEL"].ToString(); card.InHosID = dr["INHOSID"].ToString(); card.YBLX = dr["CHARGEKIND"].ToString(); card.Sex = dr["SEX"].ToString(); card.PatientName = dr["PATIENTNAME"].ToString(); …… }

委托初始化方法實例