Esempio n. 1
0
 /// <summary>
 /// Set generic event from configuration
 /// </summary>
 /// <param name="Events"></param>
 /// <param name="ctrl"></param>
 private void Set_event_handler(JToken Events, ref object ctrl)
 {
     if (ctrl is ContextMenuStrip)
     {
         ContextMenuStrip csm = (ContextMenuStrip)ctrl;
         if (((JObject)Events) == null)
         {
             Events = new JObject();
             foreach (ToolStripItem tsi in csm.Items)
             {
                 ((JObject)Events).Add(tsi.Name, tsi.Tag.ToString());
             }
             view_desc.Events = Events;
             view_desc.Write();
         }
         else
         {
             foreach (JProperty jEvent in ((JObject)Events).Properties())
             {
                 ToolStripItem tsi = csm.Items[jEvent.Name];
                 Type          tc  = tsi.GetType();
                 EventInfo     ei  = tc.GetEvent("Click");
                 ei.AddEventHandler(tsi, BuildDynamicHandle(ei.EventHandlerType, event_target_method,
                                                            View_guid, View_name, tsi.Name, ei.Name, Events[jEvent.Name].ToString()));
             }
         }
     }
     else
     {
         if (Events != null)
         {
             Type tc = ctrl.GetType();
             foreach (EventInfo ei in tc.GetEvents())
             {
                 if ((Events[ei.Name] != null) && (Events[ei.Name].ToString() != ""))
                 {
                     ei.AddEventHandler(ctrl, BuildDynamicHandle(ei.EventHandlerType, event_target_method,
                                                                 View_guid, View_name, (ctrl is Control) ? ((Control)ctrl).Name : "", ei.Name, Events[ei.Name].ToString()));
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Set generic event from configuration
 /// </summary>
 /// <param name="Events"></param>
 /// <param name="ctrl"></param>
 private void Set_event_handler(JToken Events, ref object ctrl)
 {
     if ((ctrl is ContextMenuStrip) || (ctrl is MenuStrip))
     {
         ToolStripItemCollection csmitems = (ctrl is MenuStrip)?
                                            ((MenuStrip)ctrl).Items:
                                            ((ContextMenuStrip)ctrl).Items;
         if (((JObject)Events) == null)
         {
             Events = new JObject();
             foreach (ToolStripItem tsi in csmitems)
             {
                 if ((tsi.Tag != null) && (tsi.Tag.ToString() != ""))
                 {
                     ((JObject)Events).Add(tsi.Name, tsi.Tag.ToString());
                 }
             }
             view_desc.Events = Events;
             view_desc.Write();
         }
         else
         {
             foreach (JProperty jEvent in ((JObject)Events).Properties())
             {
                 KeyValuePair <int, ToolStripItemCollection>          kp_item    = new KeyValuePair <int, ToolStripItemCollection>(0, csmitems);
                 Stack <KeyValuePair <int, ToolStripItemCollection> > stack_menu = new Stack <KeyValuePair <int, ToolStripItemCollection> >();
                 stack_menu.Push(kp_item);
                 ToolStripItem tsi = null;
                 while ((tsi == null) && (stack_menu.Count > 0))
                 {
                     kp_item = (KeyValuePair <int, ToolStripItemCollection>)stack_menu.Pop();
                     for (int i = kp_item.Key; i < kp_item.Value.Count; i++)
                     {
                         if ((kp_item.Value[i] is ToolStripMenuItem) && (((ToolStripMenuItem)kp_item.Value[i]).DropDownItems.Count > 0))
                         {
                             stack_menu.Push(new KeyValuePair <int, ToolStripItemCollection>(i + 1, kp_item.Value));
                             stack_menu.Push(new KeyValuePair <int, ToolStripItemCollection>(0, ((ToolStripMenuItem)kp_item.Value[i]).DropDownItems));
                             break;
                         }
                         else if (kp_item.Value[i].Name == jEvent.Name)
                         {
                             tsi = kp_item.Value[i];
                         }
                     }
                 }
                 Type      tc = tsi.GetType();
                 EventInfo ei = tc.GetEvent("Click");
                 ei.AddEventHandler(tsi, BuildDynamicHandle(ei.EventHandlerType, event_target_method,
                                                            View_guid, View_name, tsi.Name, ei.Name, Events[jEvent.Name].ToString()));
             }
         }
     }
     else
     {
         if (Events != null)
         {
             Type tc = ctrl.GetType();
             foreach (EventInfo ei in tc.GetEvents())
             {
                 if ((Events[ei.Name] != null) && (Events[ei.Name].ToString() != ""))
                 {
                     ei.AddEventHandler(ctrl, BuildDynamicHandle(ei.EventHandlerType, event_target_method,
                                                                 View_guid, View_name, (ctrl is Control) ? ((Control)ctrl).Name : "", ei.Name, Events[ei.Name].ToString()));
                 }
             }
         }
     }
 }