Exemple #1
0
        // Handler called when the user double-clicks the list box.
        private void ValueListBox_DoubleClick(object sender, EventArgs e)
        {
            // Ensure that the user double-clicked on an item in the list box.
            int index = ValueListBox.IndexFromPoint(ValueListBox.PointToClient(MousePosition));

            if (index != ListBox.NoMatches)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemple #2
0
        // Initializes the edit dialog to set the value of the given element.
        public void Initialize(Element element)
        {
            if ((object)element == null)
            {
                return;
            }

            Tag tag = GSF.PQDIF.Tag.GetTag(element.TagOfElement);

            // Determine whether the tag definition contains
            // a list of identifiers which can be used to
            // display the value in a more readable format
            IReadOnlyCollection <Identifier> identifiers = tag?.ValidIdentifiers ?? new List <Identifier>();

            // Some identifier collections define a set of bitfields which can be
            // combined to represent a collection of states rather than a single value
            // and these are identified by the values being represented in hexadecimal
            List <Identifier> bitFields = identifiers.Where(id => id.Value.StartsWith("0x")).ToList();

            if (bitFields.Count > 0)
            {
                // Get the value of the element
                uint value = Convert.ToUInt32(((ScalarElement)element).Get());

                // Values with bitfields will be displayed in a checked list box
                ValueCheckedListBox.Visible = true;
                ValueCheckedListBox.Focus();

                // Populate the checked list box with the valid bitfields
                foreach (Identifier bitField in bitFields)
                {
                    uint bit = Convert.ToUInt32(bitField.Value, 16);
                    ValueCheckedListBox.Items.Add(bitField.Name, (value & bit) > 0u);
                }

                // Set up the function to get the value entered by the user
                m_getValue = () => "{ " + string.Join(", ", ValueCheckedListBox.CheckedItems.Cast <string>()) + " }";
            }
            else if (identifiers.Count > 0)
            {
                // Get the value of the element
                string value = ((ScalarElement)element).Get().ToString();

                // Values with IDs will be displayed in a regular list box
                ValueListBox.Visible = true;
                ValueListBox.Focus();

                // Populate the list box with the valid identifiers
                foreach (Identifier identifier in identifiers.OrderBy(identifier => identifier.Name))
                {
                    ValueListBox.Items.Add(identifier.Name);

                    if (value == identifier.Value)
                    {
                        ValueListBox.SelectedIndex = ValueListBox.Items.Count - 1;
                    }
                }

                // Set up the function to get the value entered by the user
                m_getValue = () => ValueListBox.SelectedItem?.ToString();
            }
            else
            {
                // All other values will be displayed in an editable text box
                ValueTextBox.Visible = true;
                ValueTextBox.Focus();
                ValueTextBox.Text = element.ValueAsString();

                // Set up the function to get the value entered by the user
                m_getValue = () => ValueTextBox.Text;
            }
        }