فهرست منبع

mxg:取消永久保存菜单

mengxiangge 5 سال پیش
والد
کامیت
2ae4016337
2فایلهای تغییر یافته به همراه27 افزوده شده و 1 حذف شده
  1. 1 0
      FWindSoft/Revit/XiaoHong/LRH.csproj
  2. 26 1
      FWindSoft/Revit/XiaoHong/MainWindow.xaml.cs

+ 1 - 0
FWindSoft/Revit/XiaoHong/LRH.csproj

@@ -43,6 +43,7 @@
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
+    <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
     <Reference Include="System.Core" />

+ 26 - 1
FWindSoft/Revit/XiaoHong/MainWindow.xaml.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.IO;
 using System.Linq;
 using System.Reflection;
@@ -30,11 +31,35 @@ namespace LRH
         {
             InitializeComponent();
             this.Loaded += MainWindow_Loaded;
+        }/// <summary>
+         /// 删除指定控件的指定事件
+         /// </summary>
+         /// <param name="control"></param>
+         /// <param name="eventname"></param>
+        public void ClearEvent(System.Windows.Forms.Control control, string eventname)
+        {
+            if (control == null) return;
+            if (string.IsNullOrEmpty(eventname)) return;
+
+            BindingFlags mPropertyFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
+            BindingFlags mFieldFlags = BindingFlags.Static | BindingFlags.NonPublic;
+            Type controlType = typeof(System.Windows.Forms.Control);
+            PropertyInfo propertyInfo = controlType.GetProperty("Events", mPropertyFlags);
+            EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(control, null);
+            FieldInfo fieldInfo = (typeof(System.Windows.Forms.Control)).GetField("Event" + eventname, mFieldFlags);
+            Delegate d = eventHandlerList[fieldInfo.GetValue(control)];
+
+            if (d == null) return;
+            EventInfo eventInfo = controlType.GetEvent(eventname);
+
+            foreach (Delegate dx in d.GetInvocationList())
+                eventInfo.RemoveEventHandler(control, dx);
+
         }
 
         private void MainWindow_Loaded(object sender, RoutedEventArgs e)
         {
-            Button_Click_1(sender,e);
+            Button_Click(sender,e);
         }
 
         private void Button_Click(object sender, RoutedEventArgs e)