public override void isNewSwitch(Object sender, IsNewSwitchEventArgs e) { base.isNewSwitch(sender, e); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); try { if (e.Vector.Device == Name) { IsNewSwitch?.Invoke(this, new INDICameraSwitchEventArgs(e.Vector, e.Device)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
void IsNewSwitch(Object sender, IsNewSwitchEventArgs e) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); if ((e.Device == Device || e.Device == "") && e.Vector.Name != "" && e.Vector.Group != "") { try { if (IsHandleCreated) { this.Invoke((MethodInvoker) delegate { GroupBox vector = new GroupBox(); vector.FlatStyle = FlatStyle.Flat; AddDevice(e.Device); AddGroup(e.Vector.Group, e.Device); Control ctl = GetChild(DevicesConnected, e.Device); if (ctl != null) { ctl = GetChild(ctl, e.Device + "_Groups"); if (ctl != null) { ctl = GetChild(ctl, e.Vector.Group); ctl = GetChild(ctl, e.Vector.Group + "_AutoScrollPanel"); Panel pan = (Panel)ctl; if (!ChildPresent(pan, e.Vector.Name)) { if (GetLastChild(pan) != null) { vector.Location = new Point(GetLastChild(pan).Location.X, GetLastChild(pan).Location.Y + GetLastChild(pan).Size.Height + 5); } pan.Controls.Add(vector); vector.Name = e.Vector.Name; vector.Text = e.Vector.Label; } vector = (GroupBox)ctl.Controls.Find(e.Vector.Name, false)[0]; if (vector.Controls.Count >= e.Vector.Values.Count) { goto setSwitches; } Int32 y = 20; vector.Size = new Size(455, 20 + e.Vector.Values.Count * 28); for (int k = 1; k < vector.Parent.Controls.Count; k++) { vector.Parent.Controls[k].Location = new Point(vector.Parent.Controls[k].Location.X, vector.Parent.Controls[k - 1].Location.Y + vector.Parent.Controls[k - 1].Size.Height + 5); } foreach (INDISwitch n in e.Vector.Values) { if (e.Vector.Rule != "OneOfMany" && e.Vector.Rule != "AtMostOne") { var t = new CheckBox(); t.FlatStyle = FlatStyle.Flat; t.AutoSize = true; t.Text = n.Label; t.Name = "SWITCH_" + n.Name; t.Enabled = (e.Vector.Permission != "ro"); t.Checked = n.value; t.Location = new Point(30, y); t.CheckedChanged += valueChanged; y += 26; vector.Controls.Add(t); } else { var t = new RadioButton(); t.FlatStyle = FlatStyle.Flat; t.AutoSize = true; t.Text = n.Label; t.Name = "SELECT_" + n.Name; t.Enabled = (e.Vector.Permission != "ro"); t.Checked = n.value; t.Location = new Point(30, y); t.CheckedChanged += valueChanged; y += 26; vector.Controls.Add(t); } } setSwitches: foreach (INDISwitch n in e.Vector.Values) { if (ChildPresent(vector, "SWITCH_" + n.Name)) { ((CheckBox)vector.Controls.Find("SWITCH_" + n.Name, false)[0]).CheckedChanged -= valueChanged; ((CheckBox)vector.Controls.Find("SWITCH_" + n.Name, false)[0]).Checked = n.value; ((CheckBox)vector.Controls.Find("SWITCH_" + n.Name, false)[0]).CheckedChanged += valueChanged; } if (ChildPresent(vector, "SELECT_" + n.Name)) { ((RadioButton)vector.Controls.Find("SELECT_" + n.Name, false)[0]).CheckedChanged -= valueChanged; ((RadioButton)vector.Controls.Find("SELECT_" + n.Name, false)[0]).Checked = n.value; ((RadioButton)vector.Controls.Find("SELECT_" + n.Name, false)[0]).CheckedChanged += valueChanged; } } } } }); } } catch (Exception ex) { Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); } } }