27 lines
728 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApp1.server
{
public static class FormHelp
{
public static void RemoveAllEventHandlers(object obj, string eventName)
{
Type type = obj.GetType();
EventInfo eventInfo = type.GetEvent(eventName);
if (eventInfo != null)
{
FieldInfo fieldInfo = type.GetField(eventName, BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo != null)
{
fieldInfo.SetValue(obj, null);
}
}
}
}
}