?
Solved

capture selected or highlighted text in c#.net windows application

Posted on 2009-05-19
5
Medium Priority
?
1,987 Views
Last Modified: 2013-12-17
Hi,
i am developing windows application in c#.net.
I need to be able to copy the text from any application or document where text can be highlighted or selected(.txt, .doc, .pdf, html, .chm, .hlp, ppt, xls).

I think it is possible. but how it is possible?

appreciate any help.
Thanks in advance
0
Comment
Question by:nissiinfotechpvtltd
[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 39

Accepted Solution

by:
abel earned 1500 total points
ID: 24421375
You mean, I think, you need to be able to paste the text, is that correct? You can do so by using the clipboard functions:

// get text from clipboard, which a user copied in another app
string clipBoardText = "";
if(Clipboard.ContainsText())
    clipBoardText = Clipboard.GetText();

Open in new window

0
 

Author Comment

by:nissiinfotechpvtltd
ID: 24430961
Hi,
i am developing windows application in c#.net.
how to capture selected or hightlighted text from other applications such as pdf, chm,hlp etc..
It is possible. there are many softwares to do it.
how to do it?

pls help me
0
 
LVL 39

Assisted Solution

by:abel
abel earned 1500 total points
ID: 24431121
I believe I just explained that. Or I don't understand you correctly. If you want to do the copy from your application, you can use a SendKeys("^{C}"), which will send the Ctrl-C (copy) to the other application, if it has the focus.

Other methods may exist, but they can become extremely complex, as it highly depends on what kind of application, what kind of windows / edit classes (window-classes, not object-classes) they use and whether they are accessible from another thread. If the behave neatly, you can try sending messages to the window that is a textbox, the easy thing would be to use a WM_COPY message, but that may not be enough. If SendKeys does not work, you can use this post: http://bytes.com/groups/net-c/255335-get-selected-text-other-process (see below). It will work on the majority of cases, but not all.
0
 
LVL 39

Expert Comment

by:abel
ID: 25218425
Use want to copy text by sending keys. First answer shows how to do it without, second shows how to do it with and gives other methods as well. Suggestion: points split between http:24431121 and http:24421375
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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