hi evreydby


Read the selected text from webbrowser control and display in the texbox(only text not document text) in winforms using c#.net. y i need this means im doing spell check in winforms.

Edited 6 Years Ago by naren7: n/a

One solution is to programatically press Ctrl+C to copy the selected text to the clipboard then retrieve it from the clipboard:

private void button1_Click(object sender, EventArgs e)
        {
            //Clear the clipboard.
            Clipboard.Clear();

            //Ensure webrowser has focus
            webBrowser1.Focus();

            //press Ctrl+C and wait for process to finish
            SendKeys.SendWait("^(c)");

            // Get the text from the clipboard.
            textBox1.Text = Clipboard.GetText();

        }

One solution is to programatically press Ctrl+C to copy the selected text to the clipboard then retrieve it from the clipboard:

private void button1_Click(object sender, EventArgs e)
        {
            //Clear the clipboard.
            Clipboard.Clear();

            //Ensure webrowser has focus
            webBrowser1.Focus();

            //press Ctrl+C and wait for process to finish
            SendKeys.SendWait("^(c)");

            // Get the text from the clipboard.
            textBox1.Text = Clipboard.GetText();

        }

=====================================================
spell check

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office;
using System.Reflection;
using Microsoft.Office.Interop.Word;

namespace winspell
{
    public partial class Spellcheck : Form
    {
        public Spellcheck()
        {
            InitializeComponent();
        }

        private void btnSpell_Click(object sender, EventArgs e)
        {
            SpellCheck(textBox1, label1);
        }
    
       public void SpellCheck(TextBox tBox, Label lLbl)		
       {
    
        	int iErrorCount = 0;
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
			if (tBox.Text.Length > 0)
			{
				app.Visible=false;
				object template=Missing.Value;
				object newTemplate=Missing.Value;
				object documentType=Missing.Value;
				object visible=true;
				object optional = Missing.Value;
			
				_Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
				doc.Words.First.InsertBefore (tBox.Text );
				ProofreadingErrors we =  doc.SpellingErrors;
				iErrorCount = we.Count;

				doc.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);
	
				if (iErrorCount == 0)
					lLbl.Text = "Spelling is correct. No errors corrected ";
                    //MessageBox.Show("Spelling is correct. No errors corrected");
				else if (iErrorCount == 1)
					lLbl.Text = "Spelling is correct now. 1 error corrected ";
                    //MessageBox.Show("Spelling is correct now. 1 error corrected");
				else
					lLbl.Text = "Spelling is correct now. " + iErrorCount + " errors corrected ";
				object first=0;
				object last=doc.Characters.Count -1; 			
			
				tBox.Text = doc.Range(ref first, ref last).Text; 				
			}
			else
				lLbl.Text = "Textbox is empty";
            //MessageBox.Show("Textbox is empty");

			object saveChanges = false;
			object originalFormat = Missing.Value;
			object routeDocument = Missing.Value;
			app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
		}
	}

    
       }

how i implemented this code in webbrowser control.while selecting a text from webrowser that particular selected text must appear in spellform texbox .i get the selected text appeared in the spellcheck textbox means now i click the spell button the selected text will spellchecked by msofffice commands in .net .

Edited 6 Years Ago by Nick Evan: Fixed code-tags

I'm not sure what you are asking : /

If you are selecting all the text in one textbox then you can just use the textbox.Text property.
The code i gave you will copy selected text to the clipboard, then you can retrieve it from the clipboard and place it in a textbox. ie, the user clicks and drags with the mouse to highlight the text, then this code will copy what is highlighted and place it in a new textbox on your form.

Actually we developing html editor in winforms with some new fucntionalities such as tabcontrol ftp download and upload etc... we created a usercontrol for tabpage with webrowser control.each and evry time we clicking a newfilemenustrip tabpage incremented .
using openfilemenustrip to open the html page in my application.
if i selected some text in that html file for spell check that particular text display in the spellcheck box for SPELL CHECKINg.now spellcheck is corrected and give ok means the corrected text will display in my webrowser in winforms .this is my aim .thanks for reply. please reply to this

Edited 6 Years Ago by naren7: n/a

This article has been dead for over six months. Start a new discussion instead.