[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Code example of capturing highlight text

Posted on 2011-09-05
5
Medium Priority
?
339 Views
Last Modified: 2012-05-12
Hello,

I am looking for a small example of highlighting text and putting it into variables or showing it as selected. for example: to have 3 boxes/variables called noun, verb, adjective. in the program, we put it text, then the user can highlight a noun and click on noun button and assign it to the noun variable. The same for verb, adjective, etc...

It would be great if it could do column/block selection also. i.e The user can select a column of text  instead of just a vertical line.
0
Comment
Question by:freshgrill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 2000 total points
ID: 36486423
0
 

Author Comment

by:freshgrill
ID: 36492057
Sorry, I don't see how either of these:

1) Get the highlight text in my own program (not word under the cursor)
2) Allow me to highlight in block/column mode.

Please clarify, thanks
0
 

Author Comment

by:freshgrill
ID: 36492308
It can be in a web browser, so I have a very simple example. WHen I highlight text in the browser, it should put up a message box with the text. What is wrong in this example?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mshtml;

namespace tbrowse
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
                        //sets the default url box(textBox1.Text) to be http://www.yahoo.com/
            textBox1.Text = "http://www.yahoo.com/";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
              //Just checks to see if the url, which contains the value from the url box(textBox1.Text)
            //starts with http:// or https:// and if it doesn't, add it

            string url = textBox1.Text;

            if (!url.StartsWith("http://") &&
                !url.StartsWith("https://"))
            {
                url = "http://" + url;
            }

            webBrowser1.Navigate(new Uri(url));
        }
         //Update url Box.
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            textBox1.Text = webBrowser1.Url.ToString();
          IHTMLDocument2 htmlDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
         IHTMLSelectionObject currentSelection= htmlDocument.selection;

         if (currentSelection != null)
         {
             IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;

             if (range != null)
             {
                 MessageBox.Show(range.text);
             }
         }

        }
        //End update url Box


        //Uses the hitting of the enter key as the same as clicking the Go! button
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string url2 = textBox1.Text;

                if (!url2.StartsWith("http://") &&
                 !url2.StartsWith("https://"))
                {
                    url2 = "http://" + url2;
                }

                webBrowser1.Navigate(new Uri(url2));
            }
        }

        private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

       
   


    }
}

Open in new window

0
 

Author Comment

by:freshgrill
ID: 36492339
Ok, I added another button and know it does it when I click on the bottom.

Only thing left:

How do I enable block/column selection/highlighting instead of line highlighting?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using mshtml;

namespace tbrowse
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
                        //sets the default url box(textBox1.Text) to be http://www.yahoo.com/
            textBox1.Text = "http://www.yahoo.com/";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
              //Just checks to see if the url, which contains the value from the url box(textBox1.Text)
            //starts with http:// or https:// and if it doesn't, add it

            string url = textBox1.Text;

            if (!url.StartsWith("http://") &&
                !url.StartsWith("https://"))
            {
                url = "http://" + url;
            }

            webBrowser1.Navigate(new Uri(url));
        }
         //Update url Box.
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            textBox1.Text = webBrowser1.Url.ToString();
     

        }
        //End update url Box


        //Uses the hitting of the enter key as the same as clicking the Go! button
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string url2 = textBox1.Text;

                if (!url2.StartsWith("http://") &&
                 !url2.StartsWith("https://"))
                {
                    url2 = "http://" + url2;
                }

                webBrowser1.Navigate(new Uri(url2));
            }
        }

        private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
          

        }

        private void button2_Click(object sender, EventArgs e)
        {
            IHTMLDocument2 htmlDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
            IHTMLSelectionObject currentSelection = htmlDocument.selection;

            if (currentSelection != null)
            {
                IHTMLTxtRange range = currentSelection.createRange() as IHTMLTxtRange;

                if (range != null)
                {
                    MessageBox.Show(range.text);
                }
            }
        }

       
   


    }
}

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question