示例#1
0
 /// <summary>
 /// Send event
 /// </summary>
 /// <param name="el_name">name of control</param>
 /// <param name="id">Event type</param>
 /// <param name="lparam">long value</param>
 /// <param name="dparam">double value</param>
 /// <param name="sparam">string value</param>
 public static void SendEvent(string el_name, int id, long lparam, double dparam, string sparam)
 {
     try
     {
         foreach (var kvp in m_controllers)
         {
             GuiController controller = kvp.Value;
             if (controller.IsDiposed)
             {
                 m_controllers.Remove(kvp.Key);
                 return;
             }
             if (!controller.m_controls.ContainsKey(el_name))
             {
                 continue;
             }
             Control control = null;
             if (!controller.m_controls.TryGetValue(el_name, out control))
             {
                 return;
             }
             GuiEventType event_type = (GuiEventType)id;
             switch (event_type)
             {
             case GuiEventType.TextChange:
                 control.Invoke((MethodInvoker) delegate { control.Text = sparam; });
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         SendExceptionEvent(ex);
     }
 }
示例#2
0
        /// <summary>
        /// Create GuiController for windows form
        /// </summary>
        /// <param name="assembly_path">Path to assembly</param>
        /// <param name="form_name">Windows Form's name</param>
        /// <returns></returns>
        private static GuiController GetGuiController(string assembly_path, string form_name)
        {
            Assembly      assembly   = Assembly.LoadFile(assembly_path);
            Form          form       = FindForm(assembly, form_name);
            GuiController controller = new GuiController(assembly, form, m_global_events);

            return(controller);
        }
示例#3
0
 public static void ShowForm(string assembly_path, string form_name)
 {
     try
     {
         GuiController controller = GetGuiController(assembly_path, form_name);
         string        full_path  = assembly_path + "/" + form_name;
         m_controllers.Add(full_path, controller);
         controller.RunForm();
     }
     catch (Exception e)
     {
         SendExceptionEvent(e);
     }
 }
示例#4
0
 /// <summary>
 /// Hide Windows Form
 /// </summary>
 public static void HideForm(string assembly_path, string form_name)
 {
     try
     {
         string full_path = assembly_path + "/" + form_name;
         if (!m_controllers.ContainsKey(full_path))
         {
             return;
         }
         GuiController controller = m_controllers[full_path];
         controller.DisposeForm();
         m_controllers.Remove(full_path);
     }
     catch (Exception ex)
     {
         SendExceptionEvent(ex);
     }
 }
示例#5
0
        /// <summary>
        /// Send event
        /// </summary>
        /// <param name="el_name">name of control</param>
        /// <param name="id">Event type</param>
        /// <param name="lparam">long value</param>
        /// <param name="dparam">double value</param>
        /// <param name="sparam">string value</param>
        public static void SendEventRef(string el_name, ref int id, ref long lparam, ref double dparam, string sparam)
        {
            try
            {
                foreach (var kvp in m_controllers)
                {
                    GuiController controller = kvp.Value;
                    if (controller.IsDiposed)
                    {
                        m_controllers.Remove(kvp.Key);
                        return;
                    }
                    Control control = null;
                    if (!controller.m_controls.TryGetValue(el_name, out control))
                    {
                        SendExceptionEvent(new Exception("SendEvent: element with name '" + el_name + "' not find"));
                        continue;
                    }
                    GuiEventType event_type = (GuiEventType)id;
                    switch (event_type)
                    {
                    case GuiEventType.TextChange:
                        control.Invoke((MethodInvoker) delegate { control.Text = sparam; });
                        break;

                    case GuiEventType.CheckBoxChange:
                    {
                        CheckBox   checkBox = (CheckBox)control;
                        CheckState state    = (CheckState)lparam;
                        control.Invoke((MethodInvoker) delegate { checkBox.CheckState = state; });
                        break;
                    }

                    case GuiEventType.RadioButtonChange:
                        RadioButton radio_btn = (RadioButton)control;
                        bool        check     = lparam == 0 ? false : true;
                        control.Invoke((MethodInvoker) delegate { radio_btn.Checked = check; });
                        break;

                    case GuiEventType.ComboBoxChange:
                        ComboBox combo_box = (ComboBox)control;
                        if (combo_box.SelectedIndex != (int)lparam)
                        {
                            combo_box.SelectedIndex = (int)lparam;
                        }
                        break;

                    case GuiEventType.NumericChange:
                        NumericUpDown numeric = (NumericUpDown)control;
                        if (numeric.Value != (decimal)dparam)
                        {
                            numeric.Value = (decimal)dparam;
                        }
                        break;

                    case GuiEventType.NumericFormatChange:
                        if (control.GetType() != typeof(NumericUpDown))
                        {
                            SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'NumericStepsChange' event"));
                            break;
                        }
                        NumericUpDown num = (NumericUpDown)control;
                        num.DecimalPlaces = (int)lparam;
                        num.Increment     = (decimal)dparam;
                        break;

                    case GuiEventType.NumericMaxChange:
                        if (control.GetType() != typeof(NumericUpDown))
                        {
                            SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'NumericMaxChange' event"));
                            break;
                        }
                        NumericUpDown nummax = (NumericUpDown)control;
                        nummax.Maximum = (decimal)dparam;
                        break;

                    case GuiEventType.NumericMinChange:
                        if (control.GetType() != typeof(NumericUpDown))
                        {
                            SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'NumericMinChange' event"));
                            break;
                        }
                        NumericUpDown nummin = (NumericUpDown)control;
                        nummin.Minimum = (decimal)dparam;
                        break;

                    case GuiEventType.ElementHide:
                        if (lparam != 0)
                        {
                            control.Hide();
                        }
                        else
                        {
                            control.Show();
                        }
                        break;

                    case GuiEventType.DateTimePickerChange:
                        DateTimePicker picker = (DateTimePicker)control;
                        picker.Value = MtConverter.ToSharpDateTime(lparam);
                        break;

                    case GuiEventType.ElementEnable:
                    {
                        bool enable = lparam == 0 ? false : true;
                        if (enable != control.Enabled)
                        {
                            control.Invoke((MethodInvoker) delegate { control.Enabled = enable; });
                            controller.OnEnableChange(control, new EventArgs());
                        }
                        break;
                    }

                    case GuiEventType.MessageBox:
                    {
                        if (lparam == 1)
                        {
                            control.Enabled = false;
                        }
                        string[]          nodes = sparam.Split('|');
                        MessageBoxButtons buttons;
                        if (dparam == 0.0)
                        {
                            buttons = MessageBoxButtons.OK;
                        }
                        else
                        {
                            buttons = (MessageBoxButtons)(int)dparam;
                        }
                        if (nodes.Length == 1)
                        {
                            MessageBox.Show(sparam, sparam, buttons);
                        }
                        else if (nodes.Length == 2)
                        {
                            var icon = ParseIcon(nodes[0]);
                            if (icon == MessageBoxIcon.None)
                            {
                                MessageBox.Show(nodes[0], nodes[1], buttons);
                            }
                            else
                            {
                                MessageBox.Show(nodes[1], nodes[1], buttons, icon);
                            }
                        }
                        else
                        {
                            var icon = ParseIcon(nodes[0]);
                            MessageBox.Show(nodes[1], nodes[2], buttons, icon);
                        }
                        control.Enabled = true;
                        break;
                    }

                    case GuiEventType.AddItem:
                        if (control.GetType() != typeof(ComboBox))
                        {
                            SendExceptionEvent(new Exception("Element " + control.Name + " doesn't support 'Add Item' event"));
                            break;
                        }
                        ComboBox box = (ComboBox)control;
                        box.Items.Add(sparam);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                SendExceptionEvent(ex);
            }
        }