/// <summary>
        /// Creates a non-filtered encoding list for the combo box.
        /// </summary>
        private void CreateUnFilteredEncodingList()
        {
            // get the character sets contained in the EncodingCharacterSet class..
            var charSets = EncodingCharacterSet.GetCharacterSetList(SingleCodePageResults);

            CharacterSetComboBox.Items.Clear();

            // loop through the character sets..
            foreach (var item in charSets)
            {
                // add the character sets to the characterSetComboBox..
                CharacterSetComboBox.Items.Add(new CharacterSetComboItem {
                    CharacterSet = item, Tag = Data
                });
            }

            // set the index for the combo box..
            if (CharacterSetComboBox.Items.Count > 0)
            {
                // ..if the combo box has any items..
                CharacterSetComboBox.SelectedIndex = 0;
            }
            else
            {
                // if there are no character sets, clear the encoding combo box as well..
                EncodingComboBox.Items.Clear();
            }
        }
示例#2
0
        /// <summary>
        /// Creates the character set menu with encodings as sub menu items.
        /// </summary>
        /// <param name="parent">The parent tool strip menu item.</param>
        /// <param name="singleCodePageResults">A flag indicating if character sets containing only single encoding should be returned.</param>
        /// <param name="data">Additional data to be assigned to the encoding tool strip menu item.</param>
        public static void CreateCharacterSetMenu(ToolStripMenuItem parent, bool singleCodePageResults, object data)
        {
            // create an instance of the EncodingCharacterSet class..
            var encodingCharacterSet = new EncodingCharacterSet();

            // get the character sets contained in the EncodingCharacterSet class..
            var charSets = encodingCharacterSet.GetCharacterSetList(singleCodePageResults);

            // loop through the character sets..
            foreach (var item in charSets)
            {
                // create a "dummy" menu to contain the actual encodings for the character set..
                ToolStripMenuItem menuItem =
                    new ToolStripMenuItem(encodingCharacterSet.GetCharacterSetName(item))
                {
                    Tag = item
                };

                // set the tag to contain the character set enumeration value..

                // get the encodings for the character set..
                var encodings = encodingCharacterSet[item];

                // loop through the encodings within the character set..
                foreach (var encoding in encodings)
                {
                    if (encoding == null)
                    {
                        continue;
                    }

                    // create a menu item for the encoding..
                    DataToolStripMenuItem menuItemEncoding = new DataToolStripMenuItem(encoding.EncodingName)
                    {
                        Tag = encoding, Data = data
                    };

                    // set the Tag property to contain the encoding..

                    // set the user given additional data for the menu item..

                    // subscribe the click event..
                    menuItemEncoding.Click += MenuItemEncoding_Click;

                    // add the menu item to the character set menu..
                    menuItem.DropDownItems.Add(menuItemEncoding);
                }

                // add the character set menu item to the given parent menu..
                parent.DropDownItems.Add(menuItem);
            }
        }
        /// <summary>
        /// Selects the character set combo box and the encoding combo box selected items by given encoding.
        /// </summary>
        /// <param name="encoding">The encoding to set the selected index of the both combo boxes.</param>
        /// <param name="singleCodePageResults">A flag indicating if character sets containing only single encoding should be used.</param>
        public void SelectItemByEncoding(System.Text.Encoding encoding, bool singleCodePageResults)
        {
            var charSet = EncodingCharacterSet.GetCharacterSetsForEncoding(encoding, singleCodePageResults).FirstOrDefault();

            try
            {
                for (int i = 0; i < CharacterSetComboBox.Items.Count; i++)
                {
                    var item = (CharacterSetComboItem)CharacterSetComboBox.Items[i];
                    if (item.CharacterSet == charSet)
                    {
                        CharacterSetComboBox.SelectedIndex = i;
                        break;
                    }
                }

                for (int i = 0; i < EncodingComboBox.Items.Count; i++)
                {
                    var item = (CharacterSetComboItem)EncodingComboBox.Items[i];
                    if (!item.ContainsEncoding)
                    {
                        continue;
                    }

                    if (item.Encoding.CodePage == encoding.CodePage)
                    {
                        EncodingComboBox.SelectedIndex = i;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                LastException = ex;
            }
        }