Пример #1
0
        public EnableLanguagesDialog(IOcrEngine ocrEngine)
        {
            InitializeComponent();

            _ocrEngine = ocrEngine;
            IOcrLanguageManager languageManager = _ocrEngine.LanguageManager;

            // Get the languages supported by this engine and fill the list box
            string[] languages = languageManager.GetSupportedLanguages();
            Dictionary <string, string> languagesDictionary = new Dictionary <string, string>();

            string[] friendlyNames = new string[languages.Length];

            int i = 0;

            foreach (string language in languages)
            {
                friendlyNames[i] = MyLanguage.GetLanguageFriendlyName(language);
                languagesDictionary.Add(friendlyNames[i], language);
                i++;
            }

            Array.Sort(friendlyNames, 1, friendlyNames.Length - 1);

            foreach (string friendlyName in friendlyNames)
            {
                MyLanguage ml = new MyLanguage(languagesDictionary[friendlyName], friendlyName);
                _languagesListBox.Items.Add(ml);
            }

            // Check in the list box the current enabled languages
            string[] enabledLanguages = languageManager.GetEnabledLanguages();
            for (i = 0; i < _languagesListBox.Items.Count; i++)
            {
                MyLanguage ml = (MyLanguage)_languagesListBox.Items[i];
                foreach (string language in enabledLanguages)
                {
                    if (ml.Language == language)
                    {
                        _languagesListBox.SelectedItems.Add(ml);
                        break;
                    }
                }
            }

            if (!languageManager.SupportsEnablingMultipleLanguages || _languagesListBox.Items.Count <= 1)
            {
                _languagesListBox.SelectionMode = SelectionMode.One;
            }
        }
        public EnableLanguagesDialog(IOcrEngine ocrEngine, Image moveRightImage, Image moveLeftImage, Image moveTopImage)
        {
            InitializeComponent();

            _ocrEngine = ocrEngine;
            IOcrLanguageManager languageManager = _ocrEngine.LanguageManager;

            // Get the languages supported by this engine and fill the list box
            string[] languages        = languageManager.GetSupportedLanguages();
            string[] enabledLanguages = languageManager.GetEnabledLanguages();
            Dictionary <string, string> languagesDictionary = new Dictionary <string, string>();

            string[] friendlyNames = new string[languages.Length];

            int i = 0;

            foreach (string language in languages)
            {
                friendlyNames[i] = MyLanguage.GetLanguageFriendlyName(language);
                languagesDictionary.Add(friendlyNames[i], language);
                i++;
            }

            //Array.Sort(friendlyNames, 1, friendlyNames.Length - 1);

            i = 0;
            foreach (string friendlyName in friendlyNames)
            {
                // Don't add the enabled languages to the available languages list
                bool languageEnabled = false;
                foreach (string enabledLanguage in enabledLanguages)
                {
                    if (languagesDictionary[friendlyName].Equals(enabledLanguage))
                    {
                        languageEnabled = true;
                        break;
                    }
                }

                if (!languageEnabled)
                {
                    MyLanguage ml = new MyLanguage(languagesDictionary[friendlyName], friendlyName, i);
                    _languagesListBox.Items.Add(ml);
                }
                i++;
            }

            // Fill the 'Enabled Languages' list box
            foreach (string enabledLanguage in enabledLanguages)
            {
                i = 0;
                foreach (KeyValuePair <string, string> entry in languagesDictionary)
                {
                    if (entry.Value.Equals(enabledLanguage))
                    {
                        break;
                    }
                    i++;
                }
                string     friendlyName = MyLanguage.GetLanguageFriendlyName(enabledLanguage);
                MyLanguage ml           = new MyLanguage(enabledLanguage, friendlyName, i);
                _enabledLanguagesListBox.Items.Add(ml);
            }

            if (!languageManager.SupportsEnablingMultipleLanguages || _languagesListBox.Items.Count <= 1)
            {
                _languagesListBox.SelectionMode = SelectionMode.One;
            }

            string[] additionalLanguages = languageManager.GetAdditionalLanguages();
            if (additionalLanguages != null && additionalLanguages.Length > 0)
            {
                _additionalLabel.Text = DemosGlobalization.GetResxString(GetType(), "Resx_SupportedLanguages") + "\n" + DemosGlobalization.GetResxString(GetType(), "Resx_EngineComponents");
            }

            // Set the buttons images
            if (moveRightImage != null)
            {
                _btnMoveRight.Image = moveRightImage;
            }
            else
            {
                _btnMoveRight.Text = "→";
            }
            if (moveLeftImage != null)
            {
                _btnMoveLeft.Image = moveLeftImage;
            }
            else
            {
                _btnMoveLeft.Text = "←";
            }
            if (moveTopImage != null)
            {
                _btnMoveTop.Image = moveTopImage;
            }
            else
            {
                _btnMoveTop.Text = "↑";
            }

            UpdateUIState();
        }