Winform判断EventHandler是否已经添加

斜体部分替换成自己需要的

        private bool HasValueChangedEventHandler(DateTimePicker b)
        {
            FieldInfo f1 = typeof(DateTimePicker).GetField("onValueChanged", BindingFlags.Instance | BindingFlags.NonPublic);
            var handler = (EventHandler)f1.GetValue(b);
            return handler != null;
        }

 

你可能感兴趣的:(WinForm)