Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDateTimePickerChanged(object sender, EventArgs e)
        {
            DateTimePicker picker = (DateTimePicker)sender;
            GuiEvent       evnt   = new GuiEvent
            {
                id      = GuiEventType.DateTimePickerChange,
                el_name = picker.Name,
                lparam  = MtConverter.ToMqlDateTime(picker.Value)
            };

            m_events.Add(evnt);
        }
Ejemplo n.º 2
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);
            }
        }