Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Разработка Windows Forms > Check Spelling


Автор: shark1 24.9.2008, 21:55
Проверяю правописание ,но вот если текст небольшой то все проходит нормально,а вот если большой,то за приложением открывается word doc. и прога подвисает на некоторое время.Подскажите как это исправить.
Код

private void ckb_Spelling_CheckedChanged(object sender, EventArgs e)
        {
            if (ckb_Spelling.Checked == true)
            {
                //ckb_Spelling.Visible = false;

                label.Visible = true;
                Word.Application app = new Word.Application();

                int errors = 0;
                if (txt_File.Text.Length > 0)
                {
                    app.Visible = false;

                    // Setting these variables is comparable to passing null to the function.
                    // This is necessary because the C# null cannot be passed by reference.
                    object template = Missing.Value;
                    object newTemplate = Missing.Value;
                    object documentType = Missing.Value;
                    object visible = true;

                    Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                    doc1.Words.First.InsertBefore(txt_File.Text);
                    Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors;
                    errors = spellErrorsColl.Count;

                    object optional = Missing.Value;

                    doc1.CheckSpelling(
                        ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,
                        ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);

                    label.Text = errors + " errors corrected ";
                    object first = 0;
                    object last = doc1.Characters.Count - 1;
                    txt_File.Text = doc1.Range(ref first, ref last).Text;
                }

                object saveChanges = false;
                object originalFormat = Missing.Value;
                object routeDocument = Missing.Value;

                app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
                
            }
        }

Зарание спасибо.

Автор: Alekz 25.9.2008, 11:21
Открывать Ворд в другом потоке.
Проще всего с BackgroundWorker

Автор: shark1 25.9.2008, 19:11
Spasibo poprobuyu.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)