private void UpdateControlsFromSettings() { // update control properties with the current settings this.buttonSafeColor.BackColor = settings.SafeColor; this.buttonWarnColor.BackColor = settings.WarningColor; this.buttonDangerColor.BackColor = settings.DangerColor; this.checkBoxUseVerticalBar.Checked = settings.UseVerticalBars; this.checkBoxRunAtStartup.Checked = settings.RunAtStartup; UpdateLablesAndTrackBars(); // add all selected sensors in list box listBoxMain.Items.Clear(); List <string> nonExistSensorNames = new List <string>(); foreach (string name in settings.SelectedSensorFullnames) { bool exist = allSensors.Any(s => s.FullName() == name); if (exist) { string s = name; listBoxMain.Items.Add(s); } else { nonExistSensorNames.Add(name); } } // remove non-exist sensors from settings foreach (string name in nonExistSensorNames) { settings.SelectedSensorFullnames.Remove(name); } foreach (TreeNode node in treeViewSensors.Nodes) { foreach (TreeNode child in node.Nodes) { ISensor s = child.Tag as ISensor; if (listBoxMain.Items.Contains(s.FullName())) { child.Checked = true; } } } }
private void UpdateListBoxFromTreeView() { foreach (TreeNode node in treeViewSensors.Nodes) { IHardware h = node.Tag as IHardware; foreach (TreeNode child in node.Nodes) { ISensor s = child.Tag as ISensor; string fullname = s.FullName(); if (child.Checked && !this.listBoxMain.Items.Contains(fullname)) { listBoxMain.Items.Add(fullname); } if (!child.Checked && listBoxMain.Items.Contains(fullname)) { listBoxMain.Items.Remove(fullname); } } } }