/// <summary> /// Configure control events and properties /// </summary> /// <param name="control_guid"></param> /// <param name="ctrl"></param> /// <returns></returns> private JToken Configure(TBaseControls bCtrl, Control ctrl) { JToken Config = bCtrl.Configuration; object obj = (object)ctrl; set_properties(ref obj, Config); Set_event_handler(bCtrl.Events, ref obj); return(Config); }
public CView(CGlobals globals, String view_name) { Globals = globals; errors = new CErrors(globals); debug = new CDebug(globals); vars = new Dictionary <string, object>(); View_name = view_name; View_guid = Guid.NewGuid().ToString(); ctrls = new Dictionary <String, CtrlStruct>(); objects = new Dictionary <String, ObjStruct>(); // Create main control and descendants view_desc = new TBaseControls(Globals, View_name); CreateControl(view_name, (view_desc.Namespace != null) ? CreateTypedControl(view_name, view_desc.Namespace.ToString()) : null); // Create other objects CreateObjects(view_name); FLAG_VISTA_ACTIVA = 1; }
/// <summary> /// Generic new control from type /// </summary> /// <param name="control_guid"></param> /// <param name="type_control"></param> /// <returns></returns> private Control NewControl(String control_guid, TBaseControls bCtrl) { try { debug.add("New control: " + control_guid); // Active control by guid bCtrl.ActiveControl(control_guid); if (bCtrl.Type_str == "") { errors.add(String.Format("Error: control guid '{0}' not found in view: {1}", control_guid, Name)); } if (bCtrl.hasErrors()) { errors.add(bCtrl.jErrors); return(null); } else { // create typed control Control typed_control = null; Type type_control = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes().Where(type => type.FullName == "System.Windows.Forms." + bCtrl.Type_str)).FirstOrDefault(); if (type_control == null) { type_control = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes().Where(type => type.FullName == bCtrl.Type_str)).FirstOrDefault(); } if (type_control == null) { if (bCtrl.Type_str != null) { errors.add(String.Format("Error creating control '{0}' from type '{1}'.", control_guid, bCtrl.Type_str)); } else { errors.add(String.Format("Error creating control '{0}' from empty type.", control_guid)); } return(null); } else { typed_control = (Control)Activator.CreateInstance(type_control); typed_control.Name = control_guid; // Configure control JToken cfg = Configure(bCtrl, typed_control); // add control to list ctrls.Add(control_guid, new CtrlStruct(control_guid, typed_control, cfg, bCtrl.Events, bCtrl.Controls)); foreach (String child_control in bCtrl.Controls) { typed_control.Controls.Add(NewControl(child_control, bCtrl)); } } return(typed_control); } } catch (Exception exc) { errors.add(String.Format("Unhandled error creating control '{0}': {1}", control_guid, exc.Message)); return(null); } }
/// <summary> /// Generic new control from type /// </summary> /// <param name="control_guid"></param> /// <param name="type_control"></param> /// <returns></returns> public Control CreateControl(String control_guid) { TBaseControls bCtrl = new TBaseControls(Globals, View_name); return(NewControl(control_guid, bCtrl)); }